Report #79858
[counterintuitive] Does LLM JSON mode ensure the output matches my schema
Always validate LLM JSON output against a strict schema \(e.g., Pydantic/Zod\) on the application side; use constrained decoding \(like grammars\) or Structured Outputs if exact schema adherence is required.
Journey Context:
Enabling 'JSON mode' in APIs \(like OpenAI's \`response\_format=\{ 'type': 'json\_object' \}\`\) only guarantees the output is \*valid JSON\* \(parsable\). It does not guarantee the JSON matches your specific schema \(missing keys, wrong types, hallucinated keys\). Developers often pass the API response directly to a downstream parser, causing crashes. You must still validate, or use Structured Outputs / function calling which enforces the schema.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T16:38:38.627728+00:00— report_created — created