{"record":{"id":"f5b3e411518a28f8","repo":"BerriAI/litellm","slug":"ollamaexception-invalid-model-model-not-loaded","errorCode":null,"errorMessage":"OllamaException: Invalid Model/Model not loaded - {original_exception}","messagePattern":"OllamaException: Invalid Model/Model not loaded - (.+?)","errorType":"exception","errorClass":"BadRequestError","httpStatus":400,"severity":"error","filePath":"litellm/litellm_core_utils/exception_mapping_utils.py","lineNumber":1809,"sourceCode":"    raise cast(Exception, original_exception)\n\n\ndef _map_ollama_exception(\n    *,\n    model: str,\n    original_exception: _ProviderHTTPException,\n    custom_llm_provider: str,\n    error_str: str,\n    exception_type: str,\n    exception_provider: str,\n    extra_information: str,\n) -> None:\n    if isinstance(original_exception, dict):\n        error_str = original_exception.get(\"error\", \"\")\n    else:\n        error_str = str(original_exception)\n    if \"no such file or directory\" in error_str:\n        raise BadRequestError(\n            message=f\"OllamaException: Invalid Model/Model not loaded - {original_exception}\",\n            model=model,\n            llm_provider=\"ollama\",\n            response=getattr(original_exception, \"response\", None),\n        )\n    elif \"Failed to establish a new connection\" in error_str:\n        raise ServiceUnavailableError(\n            message=f\"OllamaException: {original_exception}\",\n            llm_provider=\"ollama\",\n            model=model,\n            response=getattr(original_exception, \"response\", None),\n        )\n    elif \"Invalid response object from API\" in error_str:\n        raise BadRequestError(\n            message=f\"OllamaException: {original_exception}\",\n            llm_provider=\"ollama\",\n            model=model,\n            response=getattr(original_exception, \"response\", None),","sourceCodeStart":1791,"sourceCodeEnd":1827,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/litellm_core_utils/exception_mapping_utils.py#L1791-L1827","documentation":"litellm maps Ollama errors containing 'no such file or directory' to litellm.BadRequestError with message 'OllamaException: Invalid Model/Model not loaded'. The named model's weights are absent from the local Ollama instance, so the runtime cannot open its files.","triggerScenarios":"Calling model='ollama/...' for a model that was never pulled (or whose tag/files vanished from OLLAMA_MODELS storage) - Ollama raises a file-not-found error and litellm surfaces it as this BadRequestError.","commonSituations":"Fresh machines where `ollama pull` was skipped, typo'd model tags ('llama3' vs 'llama3:8b'), custom OLLAMA_MODELS dirs not mounted in containers, or models removed during cleanup.","solutions":["Run `ollama pull <model>` with the exact tag you reference","Verify with `ollama list` that the tag matches the model string passed to litellm","If using a remote/custom host, confirm OLLAMA_API_BASE points at the machine that has the model","In containers, ensure the models volume is mounted and OLLAMA_MODELS matches"],"exampleFix":"# before\nlitellm.completion(model='ollama/llama3:70b', messages=msgs)  # never pulled\n# after\n# shell: ollama pull llama3:70b\nlitellm.completion(model='ollama/llama3:70b', messages=msgs)","handlingStrategy":"validation","validationCode":"import requests, os\nbase = os.environ.get('OLLAMA_API_BASE', 'http://localhost:11434')\ntags = {m['name'] for m in requests.get(f'{base}/api/tags', timeout=5).json().get('models', [])}\nassert 'llama3:70b' in tags, f'pull it first: ollama pull llama3:70b (have: {tags})'","typeGuard":"import litellm\n\ndef is_ollama_model_missing(e: Exception) -> bool:\n    return isinstance(e, litellm.BadRequestError) and 'Model not loaded' in str(e)","tryCatchPattern":"try:\n    litellm.completion(model='ollama/llama3', messages=msgs)\nexcept litellm.BadRequestError as e:\n    if 'Model not loaded' in str(e):\n        subprocess.run(['ollama', 'pull', 'llama3'])\n        return litellm.completion(model='ollama/llama3', messages=msgs)\n    raise","preventionTips":["Pre-pull models in provisioning scripts/Dockerfiles","Pin exact tags, not aliases","Health-check /api/tags at service startup"],"tags":["ollama","model-not-found","local-models","litellm"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}