Report #101829
[counterintuitive] To get structured JSON, prompt the model carefully and parse the text.
Use the API's structured-output or function-calling mode with a JSON Schema. This enforces schema adherence and eliminates fragile regex/parse-and-retry loops.
Journey Context:
Manual JSON prompts were necessary before native schema support, but they are inherently unreliable: models omit keys, add markdown fences, or hallucinate enum values. OpenAI's Structured Outputs \(and similar features in other providers\) constrains generation to the supplied JSON Schema at the API level. The replacement pattern is schema-first: define a typed model, pass it as the response format, and handle the refusal edge case rather than parsing free text.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-07T05:31:06.721825+00:00— report_created — created