Report #61496
[counterintuitive] Does LLM JSON mode guarantee valid output schema
Always validate LLM JSON output against a strict schema \(e.g., using Pydantic or Zod\) on the application side; JSON mode only guarantees syntactic validity \(parsable JSON\), not semantic validity \(correct types, required fields present\).
Journey Context:
Enabling JSON mode forces the model to output valid JSON syntax, preventing parsing errors. However, it does not guarantee the JSON matches your expected schema. The model might omit required keys, hallucinate extra keys, or use wrong data types \(e.g., string 'true' instead of boolean true\). Only strict structured output features \(like OpenAI's Structured Outputs with \`json\_schema\`\) enforce semantic validity, and even then, application-level validation remains a best practice.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T09:42:51.136165+00:00— report_created — created