Report #97500
[counterintuitive] To get JSON from an LLM, instruct it to return JSON inside the prompt
Use native structured output / schema-constrained generation when available \(OpenAI Structured Outputs, Gemini response\_schema, Anthropic tool use, Outlines/Guidance for local models\). Move the schema out of the prompt and into the API so the model cannot emit invalid JSON.
Journey Context:
Prompting for JSON leaves a 2-5% format-violation rate that requires brittle regex extraction and retry loops. Provider-native structured outputs enforce the schema at the decoding level, guarantee required keys, and often reduce token usage by sending the schema through API parameters rather than the prompt. The fallback—schema-first prompting with 'return only JSON'—is now the compatibility shim, not the default.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-25T05:13:12.095775+00:00— report_created — created