Document falling back to another model when a model refuses
Closed
DO
1mo ago+65+65+01234567890123456789-0-0-0123456789
No issue was filed for this; it's a docs recipe for a case users have run into: a coding agent hit safety refusals on tasks that another model would carry out.
The only coverage of falling back on a refusal was a note under "Finish Reason Example" in the models overview. This adds a findable section, "Falling back when a model refuses", to docs/capabilities/model-fallback.md:
- How a refusal reaches you: a successful response with
finish_reason='content_filter', with the provider's explanation inprovider_details['refusal']. That covers Anthropic'sstop_reason: 'refusal'withstop_details, and OpenAI'srefusalin Chat Completions and Responses. Because the request succeeded, the defaultfallback_ondoesn't move on. - A runnable example:
ModelFallbackwith a response handler oncontent_filter, listed withModelAPIError, which also records the refusal text.FallbackModeltakes the samefallback_on. - Things to know, each checked against
mainbefore writing:- The fallback happens per request: a refusal partway through a run moves only that request, with the history so far.
- The handler also rejects refusals that come with text. Without a fallback those become output, and
RaiseContentFilterErrorraises on them instead. fallback_on=(ContentFilterError,)never matches. The error is raised after the response was accepted, also whenRaiseContentFilterErrorraises it.- Response handlers don't apply to streamed requests. A streamed refusal is accepted with a
UserWarning, and an empty one then raisesContentFilterError; to fall back, catch it and run again withmodel=.
It also links the new section from the finish-reason note in docs/models/overview.md, and adds a "The model refuses the task" bullet in docs/troubleshooting.md.
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
- PR title is fit for the release changelog.
š¤ Generated with Claude Code