Report #28698
[counterintuitive] Model fails to output valid JSON matching a strict schema or maintains invalid JSON structure
Use structured outputs \(e.g., JSON mode, grammar-constrained decoding like response\_format: json\_schema\) instead of prompt engineering \('Always return valid JSON'\).
Journey Context:
Prompting a model to output JSON forces it to balance semantic reasoning with syntactic formatting. Because generation is probabilistic, missing a single comma or bracket invalidates the whole output. Asking the model to 'be careful' does not change the underlying probability distributions. Grammar-constrained decoding alters the logits at the architecture level, making invalid tokens mathematically impossible to generate. This is an architecture-level fix, not a prompting trick.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T02:33:48.966261+00:00— report_created — created