{"record":{"id":"3e349073fe9778ad","repo":"microsoft/semantic-kernel","slug":"ollama-text-model-id-is-required","errorCode":null,"errorMessage":"Ollama text model ID is required.","messagePattern":"Ollama text model ID is required\\.","errorType":"exception","errorClass":"ServiceInitializationError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/ollama/services/ollama_text_completion.py","lineNumber":73,"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                text_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.text_model_id:\n            raise ServiceInitializationError(\"Ollama text model ID is required.\")\n\n        super().__init__(\n            service_id=service_id or ollama_settings.text_model_id,\n            ai_model_id=ollama_settings.text_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        return OllamaTextPromptExecutionSettings\n\n    # Override from AIServiceClientBase\n    @override\n    def service_url(self) -> str | None:\n        if hasattr(self.client, \"_client\") and isinstance(self.client._client, httpx.AsyncClient):","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/ollama/services/ollama_text_completion.py#L55-L91","documentation":"Thrown by the OllamaTextCompletion constructor when the resolved text_model_id is empty or None after merging the ai_model_id argument with the OLLAMA_TEXT_MODEL_ID environment variable via OllamaSettings. The service cannot call the Ollama /api/generate endpoint without a model identifier, so it aborts initialization. It is raised as a ServiceInitializationError before any network call is made.","triggerScenarios":"Constructing OllamaTextCompletion() with ai_model_id omitted (defaults to None) while OLLAMA_TEXT_MODEL_ID is not set in the environment or .env file. Also triggered by passing ai_model_id=None explicitly, or by pointing env_file_path at a file that lacks the key.","commonSituations":"New project with no .env configured; CI/deploy environment where OLLAMA_* variables are not propagated; env var name typo (e.g. OLLAMA_TEXT_MODEL instead of OLLAMA_TEXT_MODEL_ID); switching from OllamaChatCompletion (which uses OLLAMA_CHAT_MODEL_ID) and forgetting to set the text variant.","solutions":["Pass the model name directly: OllamaTextCompletion(ai_model_id='llama3')","Set the env var: export OLLAMA_TEXT_MODEL_ID=llama3","Add OLLAMA_TEXT_MODEL_ID=llama3 to your .env and pass env_file_path='.env' to the constructor"],"exampleFix":"// before\nollama = OllamaTextCompletion()\n// after\nollama = OllamaTextCompletion(ai_model_id='llama3')","handlingStrategy":"validation","validationCode":"import os\n\nmodel_id = 'llama3'  # your intended model\nif not model_id and not os.environ.get('OLLAMA_TEXT_MODEL_ID'):\n    raise RuntimeError('OLLAMA_TEXT_MODEL_ID is not set and no ai_model_id provided')\n\nfrom semantic_kernel.connectors.ai.ollama import OllamaTextCompletion\nollama = OllamaTextCompletion(ai_model_id=model_id)","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions.service_exceptions import ServiceInitializationError\n\ntry:\n    ollama = OllamaTextCompletion()\nexcept ServiceInitializationError as e:\n    if 'text model ID is required' in str(e):\n        ollama = OllamaTextCompletion(ai_model_id=os.environ['FALLBACK_MODEL'])\n    else:\n        raise","preventionTips":["Set OLLAMA_TEXT_MODEL_ID in your .env file checked into your project template","Validate required config at application startup before constructing services","Use a settings bootstrap that fails fast with a clear message if env vars are missing"],"tags":["ollama","configuration","model-id","initialization"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}