{"record":{"id":"1a9523ddbf0c5c2c","repo":"microsoft/semantic-kernel","slug":"failed-to-create-ollama-settings","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_chat_completion.py","lineNumber":91,"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                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","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/ollama/services/ollama_chat_completion.py#L73-L109","documentation":"Raised as ServiceInitializationError when constructing the pydantic `OllamaSettings` for the Ollama chat completion service raises a `ValidationError`. Config/structure failure (local Ollama settings, no network yet). The original validation error is chained via `from ex`.","triggerScenarios":"Constructing `OllamaChatCompletion(...)` where merged config (chat_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 value, or non-string chat_model_id.","commonSituations":"OLLAMA_HOST set without scheme/port (e.g. 'localhost:11434' instead of 'http://localhost:11434'), .env path wrong, env_file_encoding set to an unsupported codec, typo'd OLLAMA_CHAT_MODEL_ID.","solutions":["Inspect the chained `ex` for the offending 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 a valid codec (default utf-8).","Pass chat_model_id directly to bypass env resolution."],"exampleFix":"# before\nsvc = OllamaChatCompletion()  # -> ServiceInitializationError\n\n# after\nsvc = OllamaChatCompletion(\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                   chat_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_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 = OllamaChatCompletion()\nexcept ServiceInitializationError as e:\n    raise SystemExit(f'Ollama chat 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 when supplied."],"tags":["ollama","chat-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"}