{"record":{"id":"ec9ee2885fc7eac7","repo":"microsoft/semantic-kernel","slug":"ollama-chat-model-id-is-required","errorCode":null,"errorMessage":"Ollama chat model ID is required.","messagePattern":"Ollama chat model ID is required\\.","errorType":"exception","errorClass":"ServiceInitializationError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/ollama/services/ollama_chat_completion.py","lineNumber":94,"sourceCode":"            ai_model_id (Optional[str]): The model name. (Optional)\n            host (Optional[str]): URL of the Ollama server, defaults to None and\n                will use the default Ollama service address: http://127.0.0.1:11434. (Optional)\n            client (Optional[AsyncClient]): A custom Ollama client to use for the service. (Optional)\n            env_file_path (str | None): Use the environment settings file as a fallback to using env vars.\n            env_file_encoding (str | None): The encoding of the environment settings file, defaults to 'utf-8'.\n        \"\"\"\n        try:\n            ollama_settings = OllamaSettings(\n                chat_model_id=ai_model_id,\n                host=host,\n                env_file_path=env_file_path,\n                env_file_encoding=env_file_encoding,\n            )\n        except ValidationError as ex:\n            raise ServiceInitializationError(\"Failed to create Ollama settings.\", ex) from ex\n\n        if not ollama_settings.chat_model_id:\n            raise ServiceInitializationError(\"Ollama chat model ID is required.\")\n\n        super().__init__(\n            service_id=service_id or ollama_settings.chat_model_id,\n            ai_model_id=ollama_settings.chat_model_id,\n            client=client or AsyncClient(host=ollama_settings.host),\n        )\n\n    # region Overriding base class methods\n\n    # Override from AIServiceClientBase\n    @override\n    def get_prompt_execution_settings_class(self) -> type[\"PromptExecutionSettings\"]:\n        \"\"\"Get the request settings class.\"\"\"\n        return OllamaChatPromptExecutionSettings\n\n    # Override from AIServiceClientBase\n    @override\n    def service_url(self) -> str | None:","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/ollama/services/ollama_chat_completion.py#L76-L112","documentation":"Raised as ServiceInitializationError when settings validated fine but `ollama_settings.chat_model_id` is still falsy. Unlike NVIDIA, Ollama has NO default model - it must be told which local model to use. Fires whether or not a host is configured.","triggerScenarios":"Constructing `OllamaChatCompletion(...)` with no ai_model_id AND no OLLAMA_CHAT_MODEL_ID in env/.env. The host may be set and the Ollama server reachable, but the connector still needs the model name.","commonSituations":"Developer assumes Ollama defaults to a model; OLLAMA_CHAT_MODEL_ID typo'd as OLLAMA_MODEL_ID; model was pulled under one name (e.g. 'llama3:8b') but a different id passed.","solutions":["Pass ai_model_id explicitly: OllamaChatCompletion(ai_model_id='llama3').","Set OLLAMA_CHAT_MODEL_ID in env/.env.","Confirm the id matches an installed model: `ollama list` on the host."],"exampleFix":"# before\nsvc = OllamaChatCompletion(host='http://localhost:11434')\n\n# after\nsvc = OllamaChatCompletion(host='http://localhost:11434', ai_model_id='llama3')","handlingStrategy":"validation","validationCode":"model_id = os.environ.get('OLLAMA_CHAT_MODEL_ID') or 'llama3'\nassert model_id, 'Ollama chat model id required'\nsvc = OllamaChatCompletion(ai_model_id=model_id, host='http://localhost:11434')","typeGuard":"def has_ollama_chat_model(**kw) -> bool:\n    return bool(kw.get('ai_model_id') or os.environ.get('OLLAMA_CHAT_MODEL_ID'))","tryCatchPattern":"from semantic_kernel.exceptions import ServiceInitializationError\ntry:\n    svc = OllamaChatCompletion()\nexcept ServiceInitializationError as e:\n    if 'chat model ID is required' in str(e):\n        svc = OllamaChatCompletion(ai_model_id='llama3')\n    else:\n        raise","preventionTips":["Always pass ai_model_id for Ollama chat (no default exists).","Confirm the id matches an installed model via `ollama list`.","Use the exact env var OLLAMA_CHAT_MODEL_ID."],"tags":["ollama","chat-completion","model-id","configuration","service-initialization-error"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}