Fix issue #3609: Add URL validation for Ollama connections #3610
+127
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix issue #3609: Add URL validation for Ollama connections
Summary
Adds early URL validation specifically for Ollama connections to provide clear, actionable error messages when users specify invalid URLs like
http://192.168.0.300:11434
. Previously, users would get a cryptic "No route to host" error from litellm after the request failed.Key Changes:
_validate_base_url()
method to validate URL format and IP addresses_validate_call_params()
to validate Ollamabase_url
andapi_base
parametersBefore:
litellm.APIConnectionError: OllamaException - [Errno 65] No route to host
After:
Invalid Ollama base_url: 'http://192.168.0.300:11434'. Please check that the URL format is correct and the IP address is valid. Example: 'http://localhost:11434' or 'http://192.168.1.100:11434'
Review & Testing Checklist for Human
model="ollama/llama3.1"
andbase_url="http://192.168.0.300:11434"
and verify it shows the new clear error message instead of the cryptic litellm errorNotes
all(part.isdigit() for part in hostname.split('.')) and len(hostname.split('.')) == 4
) which may have edge cases worth testing"ollama" in self.model.lower()
) - verify this doesn't accidentally affect other providersRequested by: João ([email protected]) via Slack
Devin session: https://app.devin.ai/sessions/c740336126bb41529cf6799c59db01a7