fix(core): map Anthropic 'refusal' finish reason to 'content_filter'

Anthropic's 'refusal' stop_reason was missing from _FINISH_REASON_MAP,
causing it to fall through to the default 'stop' — hiding the fact that
the model refused to respond due to safety policies.

Fixes #23793
This commit is contained in:
Chesars 2026-03-17 18:06:42 -03:00
parent 2405e0d400
commit 8b4a74a69c
2 changed files with 4 additions and 0 deletions

View file

@ -64,6 +64,7 @@ _FINISH_REASON_MAP: dict[str, OpenAIChatCompletionFinishReason] = {
"end_turn": "stop",
"max_tokens": "length",
"tool_use": "tool_calls",
"refusal": "content_filter",
"compaction": "length",
# Cohere
"COMPLETE": "stop",

View file

@ -74,6 +74,9 @@ class TestMapFinishReasonAnthropic:
def test_compaction(self):
assert map_finish_reason("compaction") == "length"
def test_refusal(self):
assert map_finish_reason("refusal") == "content_filter"
class TestMapFinishReasonGemini:
@pytest.mark.parametrize(