validate_model() — langchain Function Reference
Architecture documentation for the validate_model() function in _utils.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD db481aac_0d5b_6864_e8aa_47560dbb98e0["validate_model()"] 7fcdbe49_5c37_eba6_43b2_5192d6b4f79d["_utils.py"] db481aac_0d5b_6864_e8aa_47560dbb98e0 -->|defined in| 7fcdbe49_5c37_eba6_43b2_5192d6b4f79d style db481aac_0d5b_6864_e8aa_47560dbb98e0 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/ollama/langchain_ollama/_utils.py lines 12–47
def validate_model(client: Client, model_name: str) -> None:
"""Validate that a model exists in the local Ollama instance.
Args:
client: The Ollama client.
model_name: The name of the model to validate.
Raises:
ValueError: If the model is not found or if there's a connection issue.
"""
try:
response = client.list()
model_names: list[str] = [model["model"] for model in response["models"]]
if not any(
model_name == m or m.startswith(f"{model_name}:") for m in model_names
):
msg = (
f"Model `{model_name}` not found in Ollama. Please pull the "
f"model (using `ollama pull {model_name}`) or specify a valid "
f"model name. Available local models: {', '.join(model_names)}"
)
raise ValueError(msg)
except ConnectError as e:
msg = (
"Failed to connect to Ollama. Please check that Ollama is downloaded, "
"running and accessible. https://ollama.com/download"
)
raise ValueError(msg) from e
except ResponseError as e:
msg = (
"Received an error from the Ollama API. "
"Please check your Ollama server logs."
)
raise ValueError(msg) from e
Domain
Subdomains
Source
Frequently Asked Questions
What does validate_model() do?
validate_model() is a function in the langchain codebase, defined in libs/partners/ollama/langchain_ollama/_utils.py.
Where is validate_model() defined?
validate_model() is defined in libs/partners/ollama/langchain_ollama/_utils.py at line 12.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free