microsoft/semantic-kernel · error · ServiceInitializationError

Ollama chat model ID is required.

Error message

Ollama chat model ID is required.

What it means

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.

Source

Thrown at python/semantic_kernel/connectors/ai/ollama/services/ollama_chat_completion.py:94

            ai_model_id (Optional[str]): The model name. (Optional)
            host (Optional[str]): URL of the Ollama server, defaults to None and
                will use the default Ollama service address: http://127.0.0.1:11434. (Optional)
            client (Optional[AsyncClient]): A custom Ollama client to use for the service. (Optional)
            env_file_path (str | None): Use the environment settings file as a fallback to using env vars.
            env_file_encoding (str | None): The encoding of the environment settings file, defaults to 'utf-8'.
        """
        try:
            ollama_settings = OllamaSettings(
                chat_model_id=ai_model_id,
                host=host,
                env_file_path=env_file_path,
                env_file_encoding=env_file_encoding,
            )
        except ValidationError as ex:
            raise ServiceInitializationError("Failed to create Ollama settings.", ex) from ex

        if not ollama_settings.chat_model_id:
            raise ServiceInitializationError("Ollama chat model ID is required.")

        super().__init__(
            service_id=service_id or ollama_settings.chat_model_id,
            ai_model_id=ollama_settings.chat_model_id,
            client=client or AsyncClient(host=ollama_settings.host),
        )

    # region Overriding base class methods

    # Override from AIServiceClientBase
    @override
    def get_prompt_execution_settings_class(self) -> type["PromptExecutionSettings"]:
        """Get the request settings class."""
        return OllamaChatPromptExecutionSettings

    # Override from AIServiceClientBase
    @override
    def service_url(self) -> str | None:

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Pass ai_model_id explicitly: OllamaChatCompletion(ai_model_id='llama3').
  2. Set OLLAMA_CHAT_MODEL_ID in env/.env.
  3. Confirm the id matches an installed model: `ollama list` on the host.

Example fix

# before
svc = OllamaChatCompletion(host='http://localhost:11434')

# after
svc = OllamaChatCompletion(host='http://localhost:11434', ai_model_id='llama3')
Defensive patterns

Strategy: validation

Validate before calling

model_id = os.environ.get('OLLAMA_CHAT_MODEL_ID') or 'llama3'
assert model_id, 'Ollama chat model id required'
svc = OllamaChatCompletion(ai_model_id=model_id, host='http://localhost:11434')

Type guard

def has_ollama_chat_model(**kw) -> bool:
    return bool(kw.get('ai_model_id') or os.environ.get('OLLAMA_CHAT_MODEL_ID'))

Try / catch

from semantic_kernel.exceptions import ServiceInitializationError
try:
    svc = OllamaChatCompletion()
except ServiceInitializationError as e:
    if 'chat model ID is required' in str(e):
        svc = OllamaChatCompletion(ai_model_id='llama3')
    else:
        raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/ec9ee2885fc7eac7. Report an issue: GitHub.