{"record":{"id":"95da2348c246ad62","repo":"microsoft/autogen","slug":"model-is-required-for-ollamachatcompletionclient","errorCode":null,"errorMessage":"model is required for OllamaChatCompletionClient","messagePattern":"model is required for OllamaChatCompletionClient","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/models/ollama/_ollama_client.py","lineNumber":976,"sourceCode":"            response_format=StructuredOutput,\n        )\n        result = await ollama_client.create([UserMessage(content=\"Who was the first man on the moon?\", source=\"user\")])  # type: ignore\n        print(result)\n\n    Note:\n        Tool usage in ollama is stricter than in its OpenAI counterparts. While OpenAI accepts a map of [str, Any], Ollama requires a map of [str, Property] where Property is a typed object containing ``type`` and ``description`` fields. Therefore, only the keys ``type`` and ``description`` will be converted from the properties blob in the tool schema.\n\n    To view the full list of available configuration options, see the :py:class:`OllamaClientConfigurationConfigModel` class.\n\n    \"\"\"\n\n    component_type = \"model\"\n    component_config_schema = BaseOllamaClientConfigurationConfigModel\n    component_provider_override = \"autogen_ext.models.ollama.OllamaChatCompletionClient\"\n\n    def __init__(self, **kwargs: Unpack[BaseOllamaClientConfiguration]):\n        if \"model\" not in kwargs:\n            raise ValueError(\"model is required for OllamaChatCompletionClient\")\n\n        model_capabilities: Optional[ModelCapabilities] = None  # type: ignore\n        copied_args = dict(kwargs).copy()\n        if \"model_capabilities\" in kwargs:\n            model_capabilities = kwargs[\"model_capabilities\"]\n            del copied_args[\"model_capabilities\"]\n\n        model_info: Optional[ModelInfo] = None\n        if \"model_info\" in kwargs:\n            model_info = kwargs[\"model_info\"]\n            del copied_args[\"model_info\"]\n\n        client = _ollama_client_from_config(copied_args)\n        create_args = _create_args_from_config(copied_args)\n        self._raw_config: Dict[str, Any] = copied_args\n        super().__init__(\n            client=client, create_args=create_args, model_capabilities=model_capabilities, model_info=model_info\n        )","sourceCodeStart":958,"sourceCodeEnd":994,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/models/ollama/_ollama_client.py#L958-L994","documentation":"OllamaChatCompletionClient's constructor requires a 'model' keyword argument. Unlike some clients, there is no default or environment fallback: if kwargs contains no 'model' key, __init__ raises ValueError immediately. The model name is needed both for the API call and to look up default capabilities.","triggerScenarios":"Constructing OllamaChatCompletionClient() with no arguments, or passing the model under a different key (model_name=..., model_id=...) so 'model' is absent from kwargs. Also occurs when loading from a config/component dict that lacks the 'model' key.","commonSituations":"Loading client config from JSON/YAML where the model field was omitted or misspelled; component-based deserialization of a config blob saved without the model; migrating code where another client used a different parameter name.","solutions":["Pass model='...' as a keyword argument: OllamaChatCompletionClient(model='llama3.1')","If loading from config, validate the dict contains the 'model' key before constructing and fix the config source","Check for misspellings like model_name or model_name_or_path and rename to model"],"exampleFix":"# before\nclient = OllamaChatCompletionClient(host='http://localhost:11434')  # no model\n\n# after\nclient = OllamaChatCompletionClient(model='llama3.1', host='http://localhost:11434')","handlingStrategy":"validation","validationCode":"config = {'host': 'http://localhost:11434'}\nassert 'model' in config, 'Ollama client config must include the model name'\nclient = OllamaChatCompletionClient(**config)","typeGuard":null,"tryCatchPattern":"try:\n    client = OllamaChatCompletionClient(**config)\nexcept ValueError as e:\n    if 'model is required' in str(e):\n        config = {**config, 'model': os.environ['OLLAMA_MODEL']}\n        client = OllamaChatCompletionClient(**config)\n    else:\n        raise","preventionTips":["Include 'model' in every config template for Ollama clients","Validate config dicts with a schema (pydantic) before constructing components","Prefer component_config_schema-based loading which surfaces required fields"],"tags":["ollama","constructor","config","autogen"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}