Report #92355
[counterintuitive] Does LLM JSON mode guarantee output matches my schema
Always validate LLM JSON output against a strict schema \(e.g., JSON Schema, Pydantic\) on the application side. Use structured outputs \(like OpenAI's Structured Outputs / function calling\) rather than just 'JSON mode' to enforce schema constraints.
Journey Context:
Developers enable \`response\_format=\{ 'type': 'json\_object' \}\` and assume the output will match their expected keys and types. JSON mode only guarantees the output is parseable JSON \(no syntax errors\), not that it conforms to a specific schema \(e.g., missing keys, wrong types, hallucinated keys\). OpenAI's newer 'Structured Outputs' feature fixes this by constraining the grammar, but legacy JSON mode does not.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T13:36:27.256543+00:00— report_created — created