fix(auto_router): skip empty text blocks when joining Anthropic content

Filter out dict blocks with an empty or missing "text" value so that
trailing spaces are not introduced in the joined message content.
Updates the corresponding test assertion to match.
This commit is contained in:
David Schneidhoffer 2026-03-13 14:39:36 +01:00
parent 3e20cc6c52
commit f3d2887add
2 changed files with 2 additions and 2 deletions

View file

@ -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)

View file

@ -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