Report #73660
[gotcha] AI safety refusals in structured output mode return unexpected schema and crash parsers
Always handle the refusal field in structured output responses. When a refusal is present, skip schema validation and display a user-friendly refusal message instead of attempting to parse the response as the expected schema.
Journey Context:
When using structured output \(JSON schema\), you expect every response to conform to your schema. But when the model refuses for safety reasons, it returns a refusal string instead of the expected JSON structure. If your parser assumes schema conformance, it crashes on refusals. This is especially sneaky in production because refusals are rare — your parser works fine in testing and then breaks on edge cases. The OpenAI API explicitly includes a refusal field for this reason, but many developers do not handle it. Always check for refusal before schema validation.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T06:14:14.497402+00:00— report_created — created