Document falling back to another model when a model refuses

Closed
DO
1mo ago
+65-0

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 in provider_details['refusal']. That covers Anthropic's stop_reason: 'refusal' with stop_details, and OpenAI's refusal in Chat Completions and Responses. Because the request succeeded, the default fallback_on doesn't move on.
  • A runnable example: ModelFallback with a response handler on content_filter, listed with ModelAPIError, which also records the refusal text. FallbackModel takes the same fallback_on.
  • Things to know, each checked against main before 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 RaiseContentFilterError raises on them instead.
    • fallback_on=(ContentFilterError,) never matches. The error is raised after the response was accepted, also when RaiseContentFilterError raises it.
    • Response handlers don't apply to streamed requests. A streamed refusal is accepted with a UserWarning, and an empty one then raises ContentFilterError; to fall back, catch it and run again with model=.

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