From a99c37f8d67dc5a47613c923caea456e4906bd70 Mon Sep 17 00:00:00 2001 From: rodriciru Date: Mon, 6 Apr 2026 12:25:19 +0200 Subject: [PATCH] Add test for tool code execution in request transformation Add test for transform_request to include code execution tool when container upload is present. --- .../chat/test_anthropic_chat_transformation.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py b/tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py index 10a3c107367..31133eb3305 100644 --- a/tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py +++ b/tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py @@ -1939,6 +1939,23 @@ def test_transform_request_uses_dynamic_max_tokens(): assert result["max_tokens"] == 64000 +def test_transform_request_adds_tool_code_execution_when_container_upload_in_messages(): + """ + Test that transform_request correctly adds the required code_execution tool to the request + when max_tokens is not explicitly provided. + + Fixes: https://github.com/BerriAI/litellm/pull/25217 + """ + config = AnthropicConfig() + + messages = [{"role": "user", "content": "Hello"}, {type: "file", file: {file_id: 'uploadedFileId'}}] + + result = config.transform_request( + model="claude-sonnet-4-5", + messages=messages + ) + + assert len(result["tools"]) >= 1 def test_transform_request_respects_user_max_tokens(): """