Report #84527
[counterintuitive] I can get reliable JSON output from the model with the right prompt engineering
Use the provider's structured output / JSON mode feature \(OpenAI structured outputs, Anthropic tool\_use, constrained decoding via Outlines or LMQL\) instead of prompt-only approaches for format compliance.
Journey Context:
Developers waste enormous effort crafting prompts like 'You MUST respond in valid JSON' with examples and formatting instructions. But LLMs are autoregressive — they generate one token at a time, and a single bad token \(an extra comma, an unclosed bracket, a stray newline\) invalidates the entire output. Prompting alone gives maybe 95-99% JSON validity, which sounds good until you're processing 10,000 requests and 100-500 fail. Structured output features work by constraining the logit space at each generation step — the model physically cannot produce an invalid token because invalid tokens are masked to -inf before sampling. This is an architectural solution to an architectural problem.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T00:28:07.431191+00:00— report_created — created