From 5deddf55acd574d34da075a31136caa9829db812 Mon Sep 17 00:00:00 2001 From: SynapShift <127070675+SynapShift@users.noreply.github.com> Date: Thu, 22 Oct 2026 15:35:25 +0800 Subject: [PATCH] test(anthropic): preserve tools on unsupported inline removals --- ...al_pass_through_adapters_transformation.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/unit/llms/anthropic/pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.py b/tests/unit/llms/anthropic/pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.py index 1e65f56f445..7470afb22dd 100644 --- a/tests/unit/llms/anthropic/pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.py +++ b/tests/unit/llms/anthropic/pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.py @@ -5551,3 +5551,28 @@ def test_inline_tool_changes_keep_definitions_and_historical_calls(already_decla assert len(translated["messages"]) == 3 assert mapping == ({short_name: tool_name} if reactivate else {}) assert request == original + + +def test_unrecognized_tool_removal_keeps_the_existing_definition() -> None: + tool: Final = {"name": "get_weather", "input_schema": {"type": "object", "properties": {}}} + request: Final = { + "model": "hosted_vllm/test-model", + "max_tokens": 128, + "tools": [tool], + "messages": [ + {"role": "user", "content": "Check the weather"}, + { + "role": "system", + "content": [{"type": "tool_removal", "tool": {"type": "unknown", "name": "get_weather"}}], + }, + ], + } + original: Final = copy.deepcopy(request) + + translated, mapping = LiteLLMAnthropicMessagesAdapter().translate_anthropic_to_openai(request) + + assert translated["tools"] == [ + {"type": "function", "function": {"name": "get_weather", "parameters": tool["input_schema"]}} + ] + assert mapping == {} + assert request == original