microsoft/autogen · error · ValueError
Model does not support JSON output.
Error message
Model does not support JSON output.
What it means
At construction, if the resolved model_info has json_output: False but create_args contains response_format={'type': 'json_object'}, the client raises ValueError — it refuses to request JSON mode from a model declared incapable of it. This validates constructor-time config, before any request is made.
Source
Thrown at python/packages/autogen-ext/src/autogen_ext/models/ollama/_ollama_client.py:498
self._model_info = info
elif model_capabilities is None and model_info is not None:
self._model_info = model_info
self._resolved_model: Optional[str] = None
self._model_class: Optional[str] = None
if "model" in create_args:
self._resolved_model = create_args["model"]
self._model_class = _model_info.resolve_model_class(create_args["model"])
if (
not self._model_info["json_output"]
and "response_format" in create_args
and (
isinstance(create_args["response_format"], dict)
and create_args["response_format"]["type"] == "json_object"
)
):
raise ValueError("Model does not support JSON output.")
self._create_args = create_args
self._total_usage = RequestUsage(prompt_tokens=0, completion_tokens=0)
self._actual_usage = RequestUsage(prompt_tokens=0, completion_tokens=0)
# Ollama doesn't have IDs for tools, so we just increment a counter
self._tool_id = 0
@classmethod
def create_from_config(cls, config: Dict[str, Any]) -> ChatCompletionClient:
return OllamaChatCompletionClient(**config)
def get_create_args(self) -> Mapping[str, Any]:
return self._create_args
def _process_create_args(
self,
messages: Sequence[LLMMessage],
tools: Sequence[Tool | ToolSchema],View on GitHub (pinned to 027ecf0a37)
Solutions
- Remove response_format / json_output for models without JSON support, or switch to a model that supports it (e.g. llama3.1+)
- Set json_output: True in a custom model_info if you are certain the underlying Ollama model handles JSON
- Prefer the json_output parameter over raw response_format (response_format triggers deprecation warnings elsewhere in this client)
Example fix
# before
client = OllamaChatCompletionClient(model="llama2", response_format={"type": "json_object"})
# after
client = OllamaChatCompletionClient(model="llama3.1", json_output=True) Defensive patterns
Strategy: validation
Validate before calling
if create_args.get("response_format", {}).get("type") == "json_object" and not info["json_output"]:
del create_args["response_format"] # or pick a JSON-capable model
client = OllamaChatCompletionClient(client=oc, create_args=create_args, model_info=info) Type guard
def wants_json_mode(create_args: Mapping[str, Any]) -> bool:
rf = create_args.get("response_format")
return isinstance(rf, dict) and rf.get("type") == "json_object" Try / catch
try:
client = OllamaChatCompletionClient(model=name, response_format={"type": "json_object"})
except ValueError as e:
if "does not support JSON" in str(e):
client = OllamaChatCompletionClient(model="llama3.1") # JSON-capable tag
else:
raise Prevention
- Cross-check every JSON-mode config against the model's capability entry
- Prefer the json_output parameter over raw response_format dicts
- Centralize model selection + capability checks in one config validator
When it happens
Trigger: OllamaChatCompletionClient(model='llama2', response_format={'type': 'json_object'}) where the registry marks llama2 as json_output: False; passing a custom model_info with json_output: False together with a JSON response_format.
Common situations: Reusing an OpenAI-style response_format config with a smaller Ollama model; defaulting response_format globally for structured-output pipelines and switching models underneath.
Related errors
- model_info is required when model name is not a valid OpenAI
- response_format and json_output cannot be set to a Pydantic
- json_output and format cannot be set at the same time. Use j
- model_info is required for AzureAIChatCompletionClient
- Model does not support JSON output
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/3f650fa840cb963b.
Report an issue: GitHub.