{"record":{"id":"036d7e9d90b88c30","repo":"microsoft/autogen","slug":"model-does-not-support-json-output-036d7e","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/azure/_azure_ai_client.py","lineNumber":345,"sourceCode":"            self._total_usage.completion_tokens + usage.completion_tokens,\n        )\n\n    def _validate_model_info(\n        self,\n        messages: Sequence[LLMMessage],\n        tools: Sequence[Tool | ToolSchema],\n        json_output: Optional[bool | type[BaseModel]],\n        create_args: Dict[str, Any],\n    ) -> None:\n        if self.model_info[\"vision\"] is False:\n            for message in messages:\n                if isinstance(message, UserMessage):\n                    if isinstance(message.content, list) and any(isinstance(x, Image) for x in message.content):\n                        raise ValueError(\"Model does not support vision and image was provided\")\n\n        if json_output is not None:\n            if self.model_info[\"json_output\"] is False and json_output is True:\n                raise ValueError(\"Model does not support JSON output\")\n\n            if isinstance(json_output, type):\n                # TODO: we should support this in the future.\n                raise ValueError(\"Structured output is not currently supported for AzureAIChatCompletionClient\")\n\n            if json_output is True and \"response_format\" not in create_args:\n                create_args[\"response_format\"] = \"json_object\"\n\n        if self.model_info[\"json_output\"] is False and json_output is True:\n            raise ValueError(\"Model does not support JSON output\")\n        if self.model_info[\"function_calling\"] is False and len(tools) > 0:\n            raise ValueError(\"Model does not support function calling\")\n\n    async def create(\n        self,\n        messages: Sequence[LLMMessage],\n        *,\n        tools: Sequence[Tool | ToolSchema] = [],","sourceCodeStart":327,"sourceCodeEnd":363,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/models/azure/_azure_ai_client.py#L327-L363","documentation":"First of two identical guards in AzureAIChatCompletionClient._validate_model_info, inside the 'if json_output is not None' block: raised when self.model_info['json_output'] is False and the caller passes json_output=True. The model was declared as not supporting JSON mode, so the client blocks the request before setting response_format='json_object'.","triggerScenarios":"Calling create(..., json_output=True) on a client whose model_info has json_output=False; enabling a generic 'always use JSON output' wrapper around all model calls.","commonSituations":"ModelInfo copied from a template with json_output=False while the deployed model (e.g. GPT-4o) does support JSON mode; older model families (e.g. early Llama on Foundry) that genuinely lack JSON mode.","solutions":["Set json_output=True in model_info if the deployed model supports JSON mode","Otherwise drop json_output=True and parse/repair the response yourself (e.g. json.loads with retry)","Use a model/deployment that supports JSON mode for structured workflows"],"exampleFix":"# before\nmodel_info = ModelInfo(family=\"gpt-4o\", vision=True, function_calling=True,\n                      json_output=False, structured_output=False)\nawait client.create(msgs, json_output=True)\n\n# after\nmodel_info = ModelInfo(family=\"gpt-4o\", vision=True, function_calling=True,\n                      json_output=True, structured_output=False)\nawait client.create(msgs, json_output=True)","handlingStrategy":"validation","validationCode":"if json_output is True and client.model_info[\"json_output\"] is False:\n    json_output = None  # or raise a clear config error before the request","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Align model_info.json_output with the deployed model's real capabilities","Centralize capability checks in a wrapper around create()","Keep per-deployment ModelInfo dicts in config, not inline literals"],"tags":["azure","json-output","model-info","capabilities"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}