{"record":{"id":"92f0b7d0d897af9c","repo":"microsoft/autogen","slug":"response-format-must-be-a-pydantic-model-class-no","errorCode":null,"errorMessage":"response_format must be a Pydantic model class, not {type(value)}","messagePattern":"response_format must be a Pydantic model class, not (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/models/ollama/_ollama_client.py","lineNumber":540,"sourceCode":"        create_args = self._create_args.copy()\n        create_args.update(extra_create_args)\n        create_args = _create_args_from_config(create_args)\n\n        response_format_value: JsonSchemaValue | Literal[\"json\"] | None = None\n\n        if \"response_format\" in create_args:\n            warnings.warn(\n                \"Using response_format will be deprecated. Use json_output instead.\",\n                DeprecationWarning,\n                stacklevel=2,\n            )\n            value = create_args[\"response_format\"]\n            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()","sourceCodeStart":522,"sourceCodeEnd":558,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/models/ollama/_ollama_client.py#L522-L558","documentation":"Inside create(), if create_args carries a response_format (deprecated path), its value must be a Pydantic BaseModel subclass — the client takes value.model_json_schema() from it. Anything else (a string, dict, instance, or non-Pydantic class) raises this ValueError naming the actual type received.","triggerScenarios":"create(messages, extra_create_args={'response_format': {'type': 'json_object'}}) — the OpenAI-style dict is not accepted here; response_format='json'; response_format=MyModel() (instance).","commonSituations":"Copying OpenAI client kwargs into extra_create_args for Ollama; older autogen examples that used Pydantic-class response_format; migrating from a 0.2-style config dict.","solutions":["Use the supported parameter instead: json_output=True for JSON mode, or json_output=MyModel for schema-driven output","If you must use response_format, pass the Pydantic class itself: response_format=MyModel","Strip response_format from forwarded kwargs dicts before calling create()"],"exampleFix":"# before\nresult = await client.create(messages, extra_create_args={\"response_format\": {\"type\": \"json_object\"}})\n\n# after\nresult = await client.create(messages, json_output=True)","handlingStrategy":"type-guard","validationCode":"extra_create_args.pop(\"response_format\", None)  # use json_output instead\nresult = await client.create(messages, json_output=True)","typeGuard":"def is_pydantic_class(v: object) -> TypeGuard[type[BaseModel]]:\n    return isinstance(v, type) and issubclass(v, BaseModel)","tryCatchPattern":"try:\n    result = await client.create(messages, extra_create_args=extra)\nexcept ValueError as e:\n    if \"response_format must be a Pydantic model class\" in str(e):\n        extra.pop(\"response_format\", None)\n        result = await client.create(messages, extra_create_args=extra, json_output=True)\n    else:\n        raise","preventionTips":["Never forward OpenAI-style response_format dicts into Ollama extra_create_args","Standardize on json_output in all call sites","Strip deprecated keys when migrating configs between clients"],"tags":["ollama","json-output","deprecation","api-misuse"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}