Report #77957
[counterintuitive] Prompting 'Output only valid JSON with keys X and Y' without using API-level enforcement
Use the API's native Structured Outputs / JSON Mode feature with a JSON schema
Journey Context:
Prompt-based JSON formatting frequently breaks \(hallucinated keys, missing commas, markdown wrappers\). Developers historically built complex try/catch regex recovery logic to handle these failures. API-level structured outputs guarantee 100% valid JSON parsing, completely eliminating the need for output parsing boilerplate and making agentic tool use reliable.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T13:26:48.302820+00:00— report_created — created