Structured Outputs constrains completed, non-refusal model output to your schema, but the model can still refuse, returning a refusal instead of JSON. A pipeline that only handles valid JSON will crash or hang on a refusal, so the fallback must be built before the first refusal happens, not after.
Before you start
A pipeline that uses Structured Outputs, and a list of the request types that might be refused, such as disallowed content or missing data.
Detect the refusal in code
Check the finish reason or the refusal field on every reply before you parse it. A refusal is a normal API outcome, not an exception, so handle it in the main flow.
Do not retry a refusal with the same prompt: the model refused for a reason, and the same request will usually be refused again.
Send a safe reply to the user
Return a short, honest message: the request could not be completed and what the user can change, such as rephrasing or providing the missing input. Do not invent a JSON object to fill the gap.
If the refusal came from missing input, ask for exactly the missing piece. If it came from policy, say so plainly and offer the nearest allowed alternative.
Log the refusal and review the pattern
Log the prompt, the schema and the refusal reason for every refusal. Review the log weekly: a rising refusal rate on one request type means the prompt or the schema is asking for something the model will not do.
Fix the request type, not the retry count. A fallback that retries three times before giving up wastes calls and still ends in a refusal.
Practice check: fictional Maple Corner extraction, 20 requests
The table below is fictional practice material, worked out by hand from the stated outcomes. It is the expected result for the practice requests, not a run of any API.
| Outcome | Count | Handling | Verdict |
|---|---|---|---|
| Valid JSON | 17 of 20 | Parsed normally | Pass |
| Refusal, missing input | 2 of 20 | Asked for the missing field | Pass |
| Refusal, policy | 1 of 20 | Plain message given | Pass |
| Crash on refusal | 0 of 20 | None needed | Pass |
All three refusals are handled without a crash: two ask for the missing input and one gives a plain message. No request ends in an error page.
Expected result. UNTESTED: the counts in the practice table are worked out by hand, not measured by running an API. Check the refusal field on every reply in your own pipeline, and confirm that a refusal returns a safe message instead of a crash.
Limits
- A refusal is not a parse error: do not feed it to the JSON parser or count it as a schema failure.
- The fallback message should never contain invented data: an empty result stated plainly beats a fabricated one.
