Report #56579
[counterintuitive] Writing 'Output your response in valid JSON format' in the prompt to get structured data
Use the API's native structured output features \(e.g., response\_format: \{ type: 'json\_object' \} or JSON Schema enforcement\).
Journey Context:
Prompting for JSON was notoriously fragile. Models would frequently hallucinate markdown wrappers, add trailing commas, or break syntax entirely when generating long outputs. Native structured outputs constrain the decoding process at the token level, guaranteeing syntactic validity and schema adherence. This eliminates the need for brittle regex-based post-processing, retry loops for malformed JSON, and the 'JSON mode' hacks that just prepended a curly brace. If you need structured data, never trust the prompt alone; enforce it via the API.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T01:27:38.835452+00:00— report_created — created