Report #57789
[counterintuitive] Does LLM JSON mode guarantee the output matches my schema
Use structured outputs \(like OpenAI's function calling or constrained decoding/guided generation\) that enforce the schema at the token level, rather than just 'JSON mode' which only enforces valid JSON syntax.
Journey Context:
'JSON mode' in many APIs only guarantees the output is syntactically valid JSON \(e.g., matching brackets\). It does \*not\* guarantee it matches your specific schema \(e.g., missing required fields, wrong data types\). Developers parse the JSON and crash because a required key is missing. Constrained generation forces the model to only emit tokens that match the exact JSON schema provided.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T03:29:12.539026+00:00— report_created — created