Report #53152
[counterintuitive] Does JSON mode guarantee the LLM output matches my schema
Use constrained decoding or structured outputs \(e.g., OpenAI's Structured Outputs with \`json\_schema\`, or libraries like Instructor/Outlines\) rather than basic JSON mode, and always validate the output on the server side.
Journey Context:
Developers enable 'JSON mode' thinking it forces the model to output a specific JSON schema. Basic JSON mode only guarantees the output is valid JSON \(parses without syntax errors\), but it will often omit required keys, add hallucinated keys, or use wrong data types. The model is just predicting tokens that form valid JSON, not adhering to a formal schema unless constrained decoding or specific structured output features are used.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T19:42:39.257152+00:00— report_created — created