Skip to content

fix(anthropic): fail fast on refusal stop_reason instead of retrying as invalid JSON - #5616

Merged
nicoloboschi merged 2 commits into
mainfrom
fix/anthropic-refusal-no-retry
Oct 15, 2026
Merged

nicoloboschi merged 2 commits into
mainfrom
fix/anthropic-refusal-no-retry

Conversation

@nicoloboschi

Copy link
Copy Markdown
Collaborator

Fixes #5201.

The native anthropic provider gets refusals as HTTP 200 with stop_reason refusal/content_filter and an empty body. That empty body was parsed as invalid JSON and retried, so one refused chunk cost 4–16 paid calls, and the worker re-queued it.

Now both call and call_with_tools raise ProviderContentPolicyError right after the response arrives — same behaviour as #3698 for claude_code: one call, no retry at any layer.

Test: tests/test_anthropic_refusal.py (fails without the fix).

@nicoloboschi
nicoloboschi force-pushed the fix/anthropic-refusal-no-retry branch from 3acb650 to bdd9cbb Compare October 15, 2026 12:35
@nicoloboschi
nicoloboschi merged commit 5d4dcb5 into main Oct 15, 2026
116 of 117 checks passed
@nicoloboschi
nicoloboschi deleted the fix/anthropic-refusal-no-retry branch October 15, 2026 12:55
@nicoloboschi nicoloboschi mentioned this pull request Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant