{"record":{"id":"165d62c62131942c","repo":"microsoft/semantic-kernel","slug":"failed-to-create-ollama-settings-165d62","errorCode":null,"errorMessage":"Failed to create Ollama settings.","messagePattern":"Failed to create Ollama settings\\.","errorType":"exception","errorClass":"ServiceInitializationError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/ollama/services/ollama_text_completion.py","lineNumber":70,"sourceCode":"\n        Args:\n            service_id (Optional[str]): Service ID tied to the execution settings. (Optional)\n            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","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/ollama/services/ollama_text_completion.py#L52-L88","documentation":"Raised as ServiceInitializationError when constructing the pydantic `OllamaSettings` for the Ollama text completion service raises a `ValidationError`. Config/structure failure (no network yet); the original validation error is chained. This is the text-completion analogue of 1111 (chat).","triggerScenarios":"Constructing `OllamaTextCompletion(...)` where merged config (text_model_id/host/env_file_path/env_file_encoding + OLLAMA_* env) fails pydantic validation: invalid OLLAMA_HOST URL, unreadable env file, bad env_file_encoding codec, or non-string text_model_id.","commonSituations":"OLLAMA_HOST missing scheme, env_file_path wrong, env_file_encoding set to an unsupported codec, typo'd OLLAMA_TEXT_MODEL_ID.","solutions":["Inspect the chained `ex` ValidationError for the failing field.","Set OLLAMA_HOST to a full URL (http://host:port) or pass host= explicitly.","Verify env_file_path exists and env_file_encoding is valid (default utf-8).","Pass ai_model_id (text model) directly to bypass env resolution."],"exampleFix":"# before\nsvc = OllamaTextCompletion()  # -> ServiceInitializationError\n\n# after\nsvc = OllamaTextCompletion(\n    host='http://localhost:11434',\n    ai_model_id='llama3',\n)","handlingStrategy":"validation","validationCode":"from semantic_kernel.connectors.ai.ollama import OllamaSettings\nfrom pydantic import ValidationError\ntry:\n    OllamaSettings(host=os.environ.get('OLLAMA_HOST', 'http://localhost:11434'),\n                   text_model_id='llama3')\nexcept ValidationError as e:\n    raise SystemExit(f'Fix Ollama settings first: {e}')","typeGuard":"from semantic_kernel.exceptions import ServiceInitializationError\n\ndef is_ollama_text_settings_error(e: BaseException) -> bool:\n    return isinstance(e, ServiceInitializationError) and 'Failed to create Ollama settings' in str(e)","tryCatchPattern":"from semantic_kernel.exceptions import ServiceInitializationError\ntry:\n    svc = OllamaTextCompletion()\nexcept ServiceInitializationError as e:\n    raise SystemExit(f'Ollama text completion misconfigured: {e.__cause__ or e}') from e","preventionTips":["Set OLLAMA_HOST as a full http:// URL (with port).","Validate OllamaSettings with pydantic before constructing the service.","Ensure env_file_path exists and env_file_encoding is a valid codec."],"tags":["ollama","text-completion","settings","configuration","pydantic","service-initialization-error"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}