Report #26281
[counterintuitive] Does JSON mode guarantee schema-valid output
Use structured outputs with JSON Schema enforcement such as OpenAI Structured Outputs or Anthropic tool\_use rather than basic JSON mode. Always wrap parsing in try/catch with fallback logic. JSON mode only guarantees valid JSON syntax — not correct keys, types, or values.
Journey Context:
JSON mode constrains the model to produce syntactically valid JSON with proper brackets and quotes, but it does not enforce that the JSON matches your expected schema. The model can produce valid JSON with missing required fields, wrong data types, null values where you expect strings, or hallucinated keys. This gap was significant enough that OpenAI introduced Structured Outputs with JSON Schema enforcement as a separate, more reliable feature. For coding agents, assuming JSON mode means you can skip schema validation leads to runtime errors when the model produces well-formed but semantically wrong JSON. Even with Structured Outputs, validate the semantic content — the model can produce schema-conformant JSON with logically incorrect values. Always validate structure and content of model outputs, and design your tool execution layer to handle malformed or semantically wrong responses gracefully.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T22:31:00.487356+00:00— report_created — created