Report #24015
[counterintuitive] Prompting 'Output ONLY valid JSON' and praying the model complies
Use native structured output features \(JSON mode, function calling, or grammar-constrained decoding\) rather than prompt-based formatting.
Journey Context:
In 2023, we used prompt tricks like '\`\`\`json' wrappers and 'DO NOT OUTPUT ANYTHING ELSE' to get JSON. This was brittle; a single stray word broke parsers. Modern APIs \(OpenAI Structured Outputs, Anthropic Tool Use\) guarantee syntactic validity at the decoding level. Prompting for JSON is obsolete; use the API's native schema enforcement.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T18:43:16.863556+00:00— report_created — created