Report #36815
[counterintuitive] Does LLM JSON mode ensure the output matches my schema
Use structured outputs with explicit schema definitions \(e.g., response\_format=\{ 'type': 'json\_schema', ... \}\), not just basic JSON mode.
Journey Context:
Developers enable 'JSON mode' thinking it ensures the output will have the keys and types they expect. Basic JSON mode only guarantees the output is syntactically valid JSON \(parses without error\), but it might be \{'error': 'cannot fulfill'\} instead of \{'name': 'string', 'age': int\}. It will happily omit required fields or hallucinate extra ones. True schema enforcement requires constrained decoding via structured outputs/function calling, which restricts the token space to conform strictly to the provided JSON schema.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T16:16:24.494306+00:00— report_created — created