litellm/tests/unit/llms/anthropic
Mateo Wang ef7bea124e
feat(mcp): re-rank mcp_tool_search results with a rerank model (#55799)
* feat(mcp): re-rank mcp_tool_search results with a rerank model

Adds an optional `litellm_settings.mcp_tool_search.rerank_model`, a model_name from model_list.
When it is set, the keyword or embedding stage keeps up to 50 candidates and one /rerank call
through the router re-orders them before top_k is applied. The call runs the same pre-call hooks
as /rerank and is billed to the calling key. A provider error, timeout or invalid answer keeps
the base order. Rate-limit and guardrail refusals still reach the caller.

The Admin UI settings form carries the field so a save does not drop it.

* fix(mcp): resolve the caller's guardrails before the tool search rerank call

The rerank sub-call now attaches key, team, project and policy guardrails to its request
metadata the same way /rerank does, so guardrails assigned to the caller run on it.

* fix(mcp): forward the caller's model region on the tool search rerank call

The rerank sub-call now passes allowed_model_region to the router when the caller has one,
as the /rerank request setup does, so region-restricted keys keep their routing checks.

* refactor(mcp): send the tool search rerank call through the proxy's /rerank routing

The rerank sub-call now goes through route_request like /rerank, so team model aliases and blocked models apply, and a rerank_model missing from model_list keeps the base order

* fix(mcp): check the caller's model access before the tool search rerank call

A key or team whose model allowlist or per-model budget excludes the rerank model now keeps the keyword or embedding order, with no rerank call and no spend, using the same caller checks compaction's sub-call runs

* fix(mcp): count the tool search rerank call against the caller's per-model budgets

The rerank sub-call now carries the key, team, user, team member and end user model budgets in its metadata, so the budget tracker charges its spend and the caller gate refuses the next call once a budget is spent

* fix(mcp): keep the base order on every rerank failure, log rerank with caller tags and redaction opt-in, rerank the whole catalog in keyword mode, warn on an unroutable rerank_model

* fix(mcp): send inherited_tags with the tool search rerank so key and team tag rules route it like /rerank

* fix(mcp): free the key's rate-limit slot and keep the base order when any guardrail blocks the tool search rerank

* fix(mcp): bound the tool search rerank call, warn on a non-rerank rerank_model, and log it to the key's and team's callbacks

A failed rerank after the pre-call hooks now reports the dict they returned, like /rerank, so a masked query stays masked in failure logs

* test(proxy): keep the settings endpoint tests in their original layout

The previous commit reformatted the whole file. This keeps only the new rerank_model mode warning test

* fix(mcp): bound every tool search rerank step by one timeout, free its rate-limit slot on cancel, and check sub-call budgets by the sub-call's model

* fix(mcp): run each tool search rerank step in the calling task so the failure hook frees the rate-limit slot on Python 3.10 and 3.11

* fix(mcp): skip the rerank_model mode warning for names only a wildcard, default deployment or pass-through matches

---------

Co-authored-by: Xytronix <32957125+Xytronix@users.noreply.github.com>
2026-12-04 16:25:01 -08:00
..
batches refactor(cost): consolidate pricing modules (#56131) 2026-12-04 23:14:04 +00:00
chat refactor(cost): consolidate pricing modules (#56131) 2026-12-04 23:14:04 +00:00
files chore(typing): clear 670 basedpyright Any errors by validating provider payloads at the boundary (#45388) 2026-10-13 15:35:23 -07:00
messages feat(mcp): re-rank mcp_tool_search results with a rerank model (#55799) 2026-12-04 16:25:01 -08:00
pass_through refactor(anthropic): rename llms/anthropic/pass_through to llms/anthropic/messages (#48510) 2026-10-27 10:08:25 -07:00
__init__.py test(unit): add package markers to migrated unit test directories 2026-09-20 11:53:14 +00:00
anthropic_docs_refusal.py fix(anthropic): keep refusal stop_reason and stop_details on the logged response (#46104) 2026-10-14 14:42:49 -07:00
test_anthropic_common_utils.py fix(anthropic): log the advisor blocks drop_params drops, and skip turns with none (#55260) 2026-12-01 01:34:17 +00:00
test_anthropic_count_tokens_transformation.py fix(anthropic): log the advisor blocks drop_params drops, and skip turns with none (#55260) 2026-12-01 01:34:17 +00:00
test_anthropic_files_and_batches.py feat(anthropic): workload identity federation and pluggable identity sources (#44448) 2026-10-03 17:08:30 -07:00
test_anthropic_output_format_filter.py fix(bedrock): use native structured output on Haiku 5.5 and Sonnet 5.5, and fix Fable 5 and Sonnet 4.6 schema 400s (#46870) 2026-10-16 20:57:23 -07:00
test_anthropic_prompt_cache_prediction.py fix(anthropic)!: map reasoning effort none to supported thinking modes (#55848) 2026-12-02 23:33:35 +00:00
test_anthropic_reasoning_effort.py fix(anthropic)!: map reasoning effort none to supported thinking modes (#55848) 2026-12-02 23:33:35 +00:00
test_anthropic_schema_filter.py fix(bedrock): use native structured output on Haiku 5.5 and Sonnet 5.5, and fix Fable 5 and Sonnet 4.6 schema 400s (#46870) 2026-10-16 20:57:23 -07:00
test_anthropic_structured_output.py test: move tests/test_litellm/llms into tests/unit/llms (#43191) 2026-09-25 12:43:23 -07:00
test_anthropic_wif.py fix(anthropic): exchange Google identity tokens again on refresh and read oidc/ references out of ANTHROPIC_IDENTITY_TOKEN (#50583) 2026-11-07 16:48:48 -08:00
test_azure_ai_cache_pricing.py test: move tests/test_litellm/llms into tests/unit/llms (#43191) 2026-09-25 12:43:23 -07:00
test_count_tokens_oauth.py fix(count_tokens): count a history that carries a compaction block (#44784) 2026-10-30 00:11:55 -07:00
test_message_sanitization.py fix(bedrock): stop the prefill 400 when the last user message is empty (#50701) 2026-11-18 03:44:11 +00:00
test_messages_http_error_retry_cases.py fix(anthropic): keep caller tool_use ids unless the upstream rejects them (#54468) 2026-11-26 05:55:01 +00:00