Files
litellm/tests/test_litellm/router_strategy
28fe9fabae fix: complexity_router crashes on list-format message content (OpenAI multi-part messages) (#22761)
* fix: complexity_router fails on list-format message content (OpenAI multi-part messages)

When a client sends messages with list-format content
(e.g. [{"type": "text", "text": "..."}] as used by the OpenAI JS SDK
and other clients), the complexity_router's async_pre_routing_hook
skipped those messages because it only handled str content. This caused
user_message to be None, the hook returned None, and the router fell
through to selecting the complexity_router deployment itself
(model="auto_router/complexity_router") which litellm cannot dispatch,
resulting in LiteLLMUnknownProvider.

Fixes:
- Extract text from list-format content parts (type=text) before
  classifying
- Return default_model instead of None when no user message can be
  extracted, preventing the crash fallthrough
- Loosen PreRoutingHookResponse.messages type from Dict[str, str] to
  Dict[str, Any] to accommodate list-format content values

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: update messages type annotation in async_pre_routing_hook to Dict[str, Any]

Consistent with PreRoutingHookResponse.messages type change and the
list-format content support added in the previous commit.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: normalize None content to empty string in complexity_router message parsing

msg.get("content", "") returns None when the key exists with value None
(e.g. assistant messages with tool calls). Use `or ""` to normalize
None to an empty string explicitly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: strip whitespace from joined list content parts in complexity_router

Prevents leading/trailing spaces when some content parts have empty
text values (e.g. " ".join(["", "hello"]) → " hello").

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-04 16:18:49 -08:00
..
2025-07-25 07:24:42 -07:00