microsoft/autogen · error · ValueError
json_output and format cannot be set at the same time. Use j
Error message
json_output and format cannot be set at the same time. Use json_output instead.
What it means
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.
Source
Thrown at python/packages/autogen-ext/src/autogen_ext/models/ollama/_ollama_client.py:565
response_format_value = "json"
elif json_output is False:
# Text mode.
response_format_value = None
elif isinstance(json_output, type) and issubclass(json_output, BaseModel):
if response_format_value is not None:
raise ValueError(
"response_format and json_output cannot be set to a Pydantic model class at the same time. "
"Use json_output instead."
)
# Beta client mode with Pydantic model class.
response_format_value = json_output.model_json_schema()
else:
raise ValueError(f"json_output must be a boolean or a Pydantic model class, got {type(json_output)}")
if "format" in create_args:
# Handle the case where format is set from create_args.
if json_output is not None:
raise ValueError("json_output and format cannot be set at the same time. Use json_output instead.")
assert response_format_value is None
response_format_value = create_args["format"]
# Remove format from create_args to prevent passing it twice.
del create_args["format"]
# TODO: allow custom handling.
# For now we raise an error if images are present and vision is not supported
if self.model_info["vision"] is False:
for message in messages:
if isinstance(message, UserMessage):
if isinstance(message.content, list) and any(isinstance(x, Image) for x in message.content):
raise ValueError("Model does not support vision and image was provided")
if self.model_info["json_output"] is False and json_output is True:
raise ValueError("Model does not support JSON output.")
ollama_messages_nested = [to_ollama_type(m) for m in messages]
ollama_messages = [item for sublist in ollama_messages_nested for item in sublist]View on GitHub (pinned to 027ecf0a37)
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
Example fix
# before
await client.create(messages, json_output=True, extra_create_args={"format": "json"})
# after
await client.create(messages, json_output=True) Defensive patterns
Strategy: validation
Validate before calling
if json_output is not None:
create_args.pop("format", None) # json_output owns output shaping
result = await client.create(messages, extra_create_args=create_args, json_output=json_output) Try / catch
try:
result = await client.create(messages, extra_create_args=extra, json_output=jo)
except ValueError as e:
if "format cannot be set" in str(e):
extra.pop("format", None)
result = await client.create(messages, extra_create_args=extra, json_output=jo)
else:
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Model does not support JSON output.
- response_format and json_output cannot be set to a Pydantic
- model_info is required when model name is not a valid OpenAI
- model_capabilities and model_info are mutually exclusive
- response_format must be a Pydantic model class, not {type(va
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/61bddfe9497e9a8b.
Report an issue: GitHub.