Report #57521
[counterintuitive] Does LLM JSON mode guarantee output matches my schema
Always validate LLM JSON output with a strict schema validator \(like Pydantic or Zod\) and implement a retry mechanism. JSON mode only guarantees syntactic validity, not semantic schema adherence.
Journey Context:
Developers enable \`response\_format: \{ 'type': 'json\_object' \}\` and assume the output will match their expected keys and types. JSON mode only forces the output to parse as valid JSON; it frequently omits required keys, changes data types \(e.g., returning a string 'null' instead of a null object\), or hallucinates extra fields. Syntactic correctness does not imply semantic correctness.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T03:02:10.522418+00:00— report_created — created2026-06-20T03:22:00.640882+00:00— confirmed_via_duplicate_submission — confirmed