{"record":{"id":"61bddfe9497e9a8b","repo":"microsoft/autogen","slug":"json-output-and-format-cannot-be-set-at-the-same-t","errorCode":null,"errorMessage":"json_output and format cannot be set at the same time. Use json_output instead.","messagePattern":"json_output and format cannot be set 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":565,"sourceCode":"                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.\n        # For now we raise an error if images are present and vision is not supported\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 self.model_info[\"json_output\"] is False and json_output is True:\n            raise ValueError(\"Model does not support JSON output.\")\n\n        ollama_messages_nested = [to_ollama_type(m) for m in messages]\n        ollama_messages = [item for sublist in ollama_messages_nested for item in sublist]","sourceCodeStart":547,"sourceCodeEnd":583,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/models/ollama/_ollama_client.py#L547-L583","documentation":"Ollama's native API uses a 'format' parameter for output shaping. create() treats a 'format' key in create_args and the json_output parameter as mutually exclusive — setting both raises ValueError. The code then asserts response_format_value is None and adopts create_args['format'] verbatim, so ambiguity about which shaping wins is not allowed.","triggerScenarios":"create(messages, json_output=True, extra_create_args={'format': 'json'}); constructing the client with format='json' in its config and later passing json_output on individual calls; forwarding Ollama-native options dicts that include format.","commonSituations":"Client config containing native Ollama options (options={'format': 'json'} style) combined with the autogen-level json_output; migrating raw ollama-python call code into autogen extra_create_args without stripping format.","solutions":["Remove 'format' from extra_create_args/create_args and control output shape solely via json_output","Or drop json_output and pass the native format — but the json_output path is the supported autogen API","When building create_args programmatically, create_args.pop('format', None) if you also pass json_output"],"exampleFix":"# before\nawait client.create(messages, json_output=True, extra_create_args={\"format\": \"json\"})\n\n# after\nawait client.create(messages, json_output=True)","handlingStrategy":"validation","validationCode":"if json_output is not None:\n    create_args.pop(\"format\", None)  # json_output owns output shaping\nresult = await client.create(messages, extra_create_args=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 \"format cannot be set\" in str(e):\n        extra.pop(\"format\", None)\n        result = await client.create(messages, extra_create_args=extra, json_output=jo)\n    else:\n        raise","preventionTips":["Pick one output-shaping channel (json_output) and strip native 'format' from forwarded kwargs","When porting raw ollama-python code, whitelist the kwargs you forward rather than passing them all","Keep native Ollama options under options=..., not as top-level create args"],"tags":["ollama","json-output","configuration","native-options"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}