Report #50690
[counterintuitive] Does LLM JSON mode guarantee output matches my schema
Always validate LLM JSON output against a strict schema \(e.g., using Pydantic/Zod\) and implement retry logic; JSON mode only guarantees valid syntax, not semantic validity.
Journey Context:
Developers enable \`response\_format=\{ 'type': 'json\_object' \}\` and assume the output will perfectly match their expected keys and types. JSON mode forces the model to output syntactically valid JSON \(brackets close, quotes match\), but it does not guarantee the model will include the required fields, adhere to specific enums, or avoid adding hallucinated keys. It just prevents parse errors, not schema violations.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T15:33:55.092562+00:00— report_created — created