Report #69987
[counterintuitive] JSON mode guarantees the model will produce schema-compliant structured data
Use Structured Outputs with a JSON schema \(constrained decoding\) rather than JSON mode alone. JSON mode only guarantees valid JSON syntax—it does not enforce keys, types, enum values, or required fields. For guaranteed schema compliance, use OpenAI's Structured Outputs feature or equivalent constrained decoding implementations that restrict generation at the token level to only schema-valid continuations.
Journey Context:
Developers enable JSON mode \(response\_format: \{ type: 'json\_object' \}\) thinking it ensures their schema will be followed. JSON mode only ensures the output parses as valid JSON—brackets match, quotes close, etc. Models in JSON mode still hallucinate extra fields, use wrong types \('123' instead of 123\), omit required fields, or invent enum values not in the schema. OpenAI introduced Structured Outputs with constrained decoding specifically because JSON mode was insufficient. Constrained decoding works by modifying the token probability distribution at each step to only allow tokens that maintain schema validity—making it architecturally impossible to produce invalid output. This is a case where the solution required an architecture change \(constrained generation\), not better prompting. The mental model: JSON mode is a soft suggestion; constrained decoding is a hard constraint.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T23:57:51.662279+00:00— report_created — created