Report #62155
[counterintuitive] Does LLM JSON mode guarantee output matches my schema
Use Structured Outputs \(function calling/schema enforcement\) or validate LLM output with a schema validator \(e.g., Pydantic/Zod\) and retry; JSON mode only guarantees valid JSON syntax, not schema compliance.
Journey Context:
Developers enable \`response\_format=\{ "type": "json\_object" \}\` and assume the output will match their expected keys and types. JSON mode only forces the output to parse as valid JSON \(brackets match, quotes match\). It will happily return an empty object \`\{\}\` or \`\{"error": "cannot fulfill"\}\` instead of the required schema. OpenAI's newer Structured Outputs feature \(using JSON Schema\) is required for actual schema enforcement, otherwise you must validate externally.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T10:48:52.953973+00:00— report_created — created