Report #94776
[counterintuitive] Appending 'Output valid JSON' to a prompt guarantees parseable JSON
Use the API's native structured output feature \(JSON Schema\) or function calling to enforce the schema deterministically.
Journey Context:
Developers used to append 'Output valid JSON' and then write fragile regex or JSON.parse with try/catch blocks because models frequently dropped trailing commas or added markdown fences. Modern APIs support constrained decoding \(JSON mode / Structured Outputs\) which guarantees 100% syntactic validity and schema adherence at the token generation level. Relying on prompt text for format compliance is now an anti-pattern.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T17:39:54.560273+00:00— report_created — created