The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix: normalize content_filtered finish_reason (#23564)
milan-berrid29287c1c30f
diff --git a/litellm/litellm_core_utils/core_helpers.py b/litellm/litellm_core_utils/core_helpers.pyindex ee111f35929..256b16ff312 100644--- a/litellm/litellm_core_utils/core_helpers.py+++ b/litellm/litellm_core_utils/core_helpers.py@@ -96,6 +96,8 @@ _FINISH_REASON_MAP: dict[str, OpenAIChatCompletionFinishReason] = {"tool_calls": "tool_calls","function_call": "function_call","content_filter": "content_filter",+ # Anthropic Sonnet 4+ "content_filtered": "content_filter",}diff --git a/tests/test_litellm/litellm_core_utils/test_core_helpers.py b/tests/test_litellm/litellm_core_utils/test_core_helpers.pyindex 0ef76e0942d..72c3b2b077e 100644--- a/tests/test_litellm/litellm_core_utils/test_core_helpers.py+++ b/tests/test_litellm/litellm_core_utils/test_core_helpers.py@@ -59,20 +59,19 @@ VALID_OPENAI_FINISH_REASONS = {"stop", "length", "tool_calls", "function_call",class TestMapFinishReasonAnthropic:- def test_stop_sequence(self):- assert map_finish_reason("stop_sequence") == "stop"-- def test_end_turn(self):- assert map_finish_reason("end_turn") == "stop"-- def test_max_tokens(self):- assert map_finish_reason("max_tokens") == "length"-- def test_tool_use(self):- assert map_finish_reason("tool_use") == "tool_calls"-- def test_compaction(self):- assert map_finish_reason("compaction") == "length"+ @pytest.mark.parametrize(+ "provider_reason,expected",+ [+ ("stop_sequence", "stop"),+ ("end_turn", "stop"),+ ("max_tokens", "length"),+ ("tool_use", "tool_calls"),+ ("compaction", "length"),+ ("content_filtered", "content_filter"),+ ],+ )+ def test_anthropic_finish_reasons(self, provider_reason: str, expected: str) -> None:+ assert map_finish_reason(provider_reason) == expectedclass TestMapFinishReasonGemini: