Report #92843
[counterintuitive] Why LLMs randomly fail to output valid JSON or adhere to a strict schema despite explicit prompt instructions
Use constrained decoding \(e.g., JSON mode, grammar sampling, or structured outputs\) at the API level rather than relying on prompt instructions for format compliance.
Journey Context:
Developers assume that explicitly defining a JSON schema in a prompt guarantees compliance. However, autoregressive models sample from a probability distribution over the vocabulary at every step. There is always a non-zero probability that the model samples a token that breaks the schema \(like a stray comma or quote\). Prompting cannot mathematically zero out these probabilities; only constrained decoding can mask invalid tokens.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T14:25:30.321170+00:00— report_created — created