{"record":{"id":"3f650fa840cb963b","repo":"microsoft/autogen","slug":"model-does-not-support-json-output-3f650f","errorCode":null,"errorMessage":"Model does not support JSON output.","messagePattern":"Model does not support JSON output\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/models/ollama/_ollama_client.py","lineNumber":498,"sourceCode":"            self._model_info = info\n        elif model_capabilities is None and model_info is not None:\n            self._model_info = model_info\n\n        self._resolved_model: Optional[str] = None\n        self._model_class: Optional[str] = None\n        if \"model\" in create_args:\n            self._resolved_model = create_args[\"model\"]\n            self._model_class = _model_info.resolve_model_class(create_args[\"model\"])\n\n        if (\n            not self._model_info[\"json_output\"]\n            and \"response_format\" in create_args\n            and (\n                isinstance(create_args[\"response_format\"], dict)\n                and create_args[\"response_format\"][\"type\"] == \"json_object\"\n            )\n        ):\n            raise ValueError(\"Model does not support JSON output.\")\n\n        self._create_args = create_args\n        self._total_usage = RequestUsage(prompt_tokens=0, completion_tokens=0)\n        self._actual_usage = RequestUsage(prompt_tokens=0, completion_tokens=0)\n        # Ollama doesn't have IDs for tools, so we just increment a counter\n        self._tool_id = 0\n\n    @classmethod\n    def create_from_config(cls, config: Dict[str, Any]) -> ChatCompletionClient:\n        return OllamaChatCompletionClient(**config)\n\n    def get_create_args(self) -> Mapping[str, Any]:\n        return self._create_args\n\n    def _process_create_args(\n        self,\n        messages: Sequence[LLMMessage],\n        tools: Sequence[Tool | ToolSchema],","sourceCodeStart":480,"sourceCodeEnd":516,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/models/ollama/_ollama_client.py#L480-L516","documentation":"At construction, if the resolved model_info has json_output: False but create_args contains response_format={'type': 'json_object'}, the client raises ValueError — it refuses to request JSON mode from a model declared incapable of it. This validates constructor-time config, before any request is made.","triggerScenarios":"OllamaChatCompletionClient(model='llama2', response_format={'type': 'json_object'}) where the registry marks llama2 as json_output: False; passing a custom model_info with json_output: False together with a JSON response_format.","commonSituations":"Reusing an OpenAI-style response_format config with a smaller Ollama model; defaulting response_format globally for structured-output pipelines and switching models underneath.","solutions":["Remove response_format / json_output for models without JSON support, or switch to a model that supports it (e.g. llama3.1+)","Set json_output: True in a custom model_info if you are certain the underlying Ollama model handles JSON","Prefer the json_output parameter over raw response_format (response_format triggers deprecation warnings elsewhere in this client)"],"exampleFix":"# before\nclient = OllamaChatCompletionClient(model=\"llama2\", response_format={\"type\": \"json_object\"})\n\n# after\nclient = OllamaChatCompletionClient(model=\"llama3.1\", json_output=True)","handlingStrategy":"validation","validationCode":"if create_args.get(\"response_format\", {}).get(\"type\") == \"json_object\" and not info[\"json_output\"]:\n    del create_args[\"response_format\"]  # or pick a JSON-capable model\nclient = OllamaChatCompletionClient(client=oc, create_args=create_args, model_info=info)","typeGuard":"def wants_json_mode(create_args: Mapping[str, Any]) -> bool:\n    rf = create_args.get(\"response_format\")\n    return isinstance(rf, dict) and rf.get(\"type\") == \"json_object\"","tryCatchPattern":"try:\n    client = OllamaChatCompletionClient(model=name, response_format={\"type\": \"json_object\"})\nexcept ValueError as e:\n    if \"does not support JSON\" in str(e):\n        client = OllamaChatCompletionClient(model=\"llama3.1\")  # JSON-capable tag\n    else:\n        raise","preventionTips":["Cross-check every JSON-mode config against the model's capability entry","Prefer the json_output parameter over raw response_format dicts","Centralize model selection + capability checks in one config validator"],"tags":["ollama","json-output","configuration","model-info"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}