diff --git a/litellm/router_strategy/auto_router/auto_router.py b/litellm/router_strategy/auto_router/auto_router.py index 922ffe90239..a980f7f8164 100644 --- a/litellm/router_strategy/auto_router/auto_router.py +++ b/litellm/router_strategy/auto_router/auto_router.py @@ -123,7 +123,7 @@ class AutoRouter(CustomLogger): raw_content = user_message.get("content", "") # Handle Anthropic-style content blocks: [{"type": "text", "text": "..."}] if isinstance(raw_content, list): - message_content = " ".join(block.get("text", "") for block in raw_content if isinstance(block, dict)) + message_content = " ".join(block.get("text", "") for block in raw_content if isinstance(block, dict) and block.get("text", "")) else: message_content = str(raw_content) route_choice: Optional[Union[RouteChoice, List[RouteChoice]]] = self.routelayer(text=message_content) diff --git a/tests/test_litellm/router_strategy/test_auto_router.py b/tests/test_litellm/router_strategy/test_auto_router.py index c0d7bc0ab46..43786cbd53e 100644 --- a/tests/test_litellm/router_strategy/test_auto_router.py +++ b/tests/test_litellm/router_strategy/test_auto_router.py @@ -232,6 +232,6 @@ class TestAutoRouter: ) # Assert: only dict blocks contribute; "text" defaults to "" when missing - mock_routelayer.assert_called_once_with(text="What is the weather today? In Paris. ") + mock_routelayer.assert_called_once_with(text="What is the weather today? In Paris.") assert result is not None assert result.messages == messages