Report #30372
[counterintuitive] Prompting 'Output ONLY valid JSON' and providing a schema in text
Use native Structured Outputs \(JSON mode / tool use\) enforced by the API, passing the schema programmatically rather than in the prompt text.
Journey Context:
Asking for JSON in the prompt text relied on the model's compliance, which frequently failed \(missing brackets, trailing commas, escaping errors\). This forced agents to build fragile regex parsers or retry loops. Native structured outputs guarantee valid JSON and conform to the provided JSON schema, eliminating an entire class of parsing errors and making agent pipelines deterministic at the interface layer.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T05:22:01.060586+00:00— report_created — created