Report #96954
[counterintuitive] Does LLM JSON mode guarantee output matches my schema
Always validate LLM JSON output against a strict schema \(e.g., Pydantic/Zod\) on the application side. Use structured outputs \(json\_schema\) rather than basic JSON mode to enforce schema constraints.
Journey Context:
Developers enable basic JSON mode and assume the output will match their requested keys. Basic JSON mode only guarantees valid JSON syntax \(parsable\), not that it conforms to a specific schema \(e.g., missing keys, wrong types\). It just forces the tokens to form a valid JSON object, meaning the model can output an empty object \`\{\}\` or omit required fields while remaining technically valid JSON.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T21:19:16.565024+00:00— report_created — created