Report #41624
[counterintuitive] Prompting 'Output ONLY valid JSON' to get structured data from LLMs
Use the API's native structured output features \(e.g., JSON mode, function calling, or response\_format\) with a provided schema.
Journey Context:
Developers used to rely on prompt tricks \('Do not output markdown, only JSON'\) to get structured data, leading to fragile parsing and frequent syntax errors. Modern APIs constrain the decoding process at the token level to guarantee schema adherence. Prompt-based JSON enforcement is obsolete and brittle compared to grammar-constrained decoding, which mathematically ensures the output conforms to the provided JSON schema.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T00:20:18.148012+00:00— report_created — created