microsoft/autogen · error · ValueError
json_output must be a boolean or a Pydantic model class, got
Error message
json_output must be a boolean or a Pydantic model class, got {type(json_output)} What it means
The json_output parameter of OllamaChatCompletionClient.create() must be None, a bool, or a Pydantic BaseModel subclass. The final else in the elif chain raises ValueError echoing the received type. Like error 803, passing a BaseModel *instance* (not the class) is the most frequent trigger, along with strings from config files.
Source
Thrown at python/packages/autogen-ext/src/autogen_ext/models/ollama/_ollama_client.py:560
if json_output is not None:
if self.model_info["json_output"] is False and json_output is True:
raise ValueError("Model does not support JSON output.")
if json_output is True:
# JSON mode.
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")
View on GitHub (pinned to 027ecf0a37)
Solutions
- Pass the class: json_output=MyModel
- Coerce config values before the call: parse 'true'/'false' strings to bool
- Validate at the boundary: accept only bool | None | type[BaseModel] in your own wrapper's signature
Example fix
# before await client.create(messages, json_output=SummaryResult()) # instance # after await client.create(messages, json_output=SummaryResult) # class
Defensive patterns
Strategy: type-guard
Validate before calling
def normalize_json_output(v: object) -> bool | type[BaseModel] | None:
if v is None or isinstance(v, bool):
return v
if isinstance(v, type) and issubclass(v, BaseModel):
return v
if isinstance(v, str) and v.lower() in ("true", "false"):
return v.lower() == "true"
raise TypeError(f"unusable json_output: {v!r}")
result = await client.create(messages, json_output=normalize_json_output(cfg.get("json_output"))) Type guard
def is_valid_ollama_json_output(v: object) -> TypeGuard[bool | type[BaseModel] | None]:
return v is None or isinstance(v, bool) or (isinstance(v, type) and issubclass(v, BaseModel)) Try / catch
try:
result = await client.create(messages, json_output=jo)
except ValueError as e:
if "json_output must be a boolean or a Pydantic model class" in str(e):
result = await client.create(messages, json_output=None)
else:
raise Prevention
- Pass BaseModel classes, never instances
- Coerce string booleans from config before the call
- Type wrapper parameters as Optional[bool | type[BaseModel]] for static checking
When it happens
Trigger: json_output=MyModel() (instance); json_output='True' or 'true' from YAML/JSON config; json_output=1; forwarding a TypedDict or dataclass class.
Common situations: Deserialized configuration where booleans arrive as strings; passing a pre-built schema instance from another module; generic wrapper code that forwards arbitrary kwargs into json_output.
Related errors
- json_output must be a boolean, a BaseModel subclass or None.
- response_format must be a Pydantic model class, not {type(va
- The from field must be null or the agent name
- Invalid Role
- Unknown content type: {part}
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/61bb9cf55ed8c816.
Report an issue: GitHub.