{"record":{"id":"ea0b299483ae6c4f","repo":"microsoft/autogen","slug":"response-format-and-json-output-cannot-be-set-to-a","errorCode":null,"errorMessage":"response_format and json_output cannot be set to a Pydantic model class at the same time. Use json_output instead.","messagePattern":"response_format and json_output cannot be set to a Pydantic model class at the same time\\. Use json_output instead\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/models/ollama/_ollama_client.py","lineNumber":553,"sourceCode":"            if isinstance(value, type) and issubclass(value, BaseModel):\n                response_format_value = value.model_json_schema()\n                # Remove response_format from create_args to prevent passing it twice.\n                del create_args[\"response_format\"]\n            else:\n                raise ValueError(f\"response_format must be a Pydantic model class, not {type(value)}\")\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            if json_output is True:\n                # JSON mode.\n                response_format_value = \"json\"\n            elif json_output is False:\n                # Text mode.\n                response_format_value = None\n            elif isinstance(json_output, type) and issubclass(json_output, BaseModel):\n                if response_format_value is not None:\n                    raise ValueError(\n                        \"response_format and json_output cannot be set to a Pydantic model class at the same time. \"\n                        \"Use json_output instead.\"\n                    )\n                # Beta client mode with Pydantic model class.\n                response_format_value = json_output.model_json_schema()\n            else:\n                raise ValueError(f\"json_output must be a boolean or a Pydantic model class, got {type(json_output)}\")\n\n        if \"format\" in create_args:\n            # Handle the case where format is set from create_args.\n            if json_output is not None:\n                raise ValueError(\"json_output and format cannot be set at the same time. Use json_output instead.\")\n            assert response_format_value is None\n            response_format_value = create_args[\"format\"]\n            # Remove format from create_args to prevent passing it twice.\n            del create_args[\"format\"]\n\n        # TODO: allow custom handling.","sourceCodeStart":535,"sourceCodeEnd":571,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/models/ollama/_ollama_client.py#L535-L571","documentation":"create() rejects specifying a Pydantic schema through both channels at once: a BaseModel class in create_args['response_format'] (deprecated path, which sets response_format_value) and another BaseModel class as json_output. Because response_format_value is not None when json_output is a BaseModel subclass, this ValueError fires telling you to use json_output only.","triggerScenarios":"create(messages, extra_create_args={'response_format': MyModel}, json_output=MyModel); config templating that sets both a legacy response_format and the new json_output schema.","commonSituations":"Half-finished migration from response_format to json_output leaving both keys in a merged config; shared request-builder code appending defaults for both parameters.","solutions":["Keep only json_output=MyModel and remove response_format from extra_create_args","Sanitize merged configs: if both keys hold Pydantic classes, drop response_format","Prefer json_output everywhere — response_format in this client already emits DeprecationWarning"],"exampleFix":"# before\nawait client.create(messages, extra_create_args={\"response_format\": StepPlan}, json_output=StepPlan)\n\n# after\nawait client.create(messages, json_output=StepPlan)","handlingStrategy":"validation","validationCode":"if \"response_format\" in extra_create_args and json_output is not None:\n    extra_create_args = {k: v for k, v in extra_create_args.items() if k != \"response_format\"}\nresult = await client.create(messages, extra_create_args=extra_create_args, json_output=json_output)","typeGuard":null,"tryCatchPattern":"try:\n    result = await client.create(messages, extra_create_args=extra, json_output=jo)\nexcept ValueError as e:\n    if \"cannot be set to a Pydantic model class at the same time\" in str(e):\n        extra.pop(\"response_format\", None)\n        result = await client.create(messages, extra_create_args=extra, json_output=jo)\n    else:\n        raise","preventionTips":["Finish the response_format -> json_output migration; never carry both","Sanitize merged config dicts to drop legacy keys","Lint call sites for response_format usage in Ollama paths"],"tags":["ollama","json-output","deprecation","configuration"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}