Report #55773
[counterintuitive] Does LLM JSON mode guarantee output matches my schema
Use structured outputs with a provided JSON Schema \(constrained decoding\) rather than just setting \`response\_format: \{ "type": "json\_object" \}\`.
Journey Context:
Early JSON modes just ensured the output was parseable JSON \(valid syntax\), but developers assumed it meant 'schema-compliant mode'. An LLM returning \`\{\}\` or missing required keys is valid JSON but breaks the application. Modern constrained generation \(like OpenAI's Structured Outputs or grammar-based sampling\) forces the generation to adhere strictly to a specific JSON schema at the token level, guaranteeing both syntax and schema validity.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T00:06:30.450609+00:00— report_created — created