Report #52964
[counterintuitive] Prompting 'Output valid JSON' and expecting the model to never fail, relying solely on prompt text for structure
Use API-level structured output features \(e.g., OpenAI Structured Outputs, Anthropic tool use\) with a defined schema rather than prompt-only JSON enforcement.
Journey Context:
In 2023, developers spent hours tweaking prompts \('Ensure the JSON is valid and never output markdown fences'\) to get reliable JSON. Modern APIs now support constrained decoding \(grammar-based generation\) where the model is mathematically forced to output valid JSON conforming to a Pydantic schema. Prompt-only JSON is brittle and prone to escaping errors; API-level enforcement is deterministic and eliminates the need for 'output valid JSON' folklore.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T19:23:36.908166+00:00— report_created — created