Report #46951
[counterintuitive] Does LLM JSON mode guarantee the output matches my schema
Use structured outputs / function calling with a strict JSON schema, or implement a validation layer \(like Pydantic\) with retries. JSON mode only guarantees valid JSON syntax, not schema adherence.
Journey Context:
Developers enable \`response\_format=\{ 'type': 'json\_object' \}\` assuming it forces the model to output the exact keys and types they specified in the prompt. JSON mode only forces the output to parse as valid JSON \(e.g., matching brackets\). The model can still omit required keys, output wrong data types, or hallucinate extra keys. OpenAI's newer 'Structured Outputs' with strict schema enforcement is required for true schema guarantees.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T09:16:52.626433+00:00— report_created — created