From 154bb532e0f084426fba4e1b649dbefa3e14b446 Mon Sep 17 00:00:00 2001 From: Shifat Islam Santo Date: Thu, 27 Aug 2026 18:07:30 -0500 Subject: [PATCH] fix(anthropic): let add_code_execution_tool take the pass-through message union The translator now emits role=system inside messages for models that accept it, so anthropic_messages_pt returns the pass-through union. add_code_execution_tool still declared the narrower user/assistant union while only ever reading content, so upstream's strip_advisor_blocks_from_messages call in between made the mismatch visible to the type checker. --- litellm/llms/anthropic/chat/transformation.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/litellm/llms/anthropic/chat/transformation.py b/litellm/llms/anthropic/chat/transformation.py index c1b2cb2985e..81ceb3eff5e 100644 --- a/litellm/llms/anthropic/chat/transformation.py +++ b/litellm/llms/anthropic/chat/transformation.py @@ -31,7 +31,7 @@ from litellm.types.llms.anthropic import ( ANTHROPIC_ADVISOR_TOOL_TYPE, ANTHROPIC_BETA_HEADER_VALUES, ANTHROPIC_HOSTED_TOOLS, - AllAnthropicMessageValues, + AllAnthropicPassThroughMessageValues, AllAnthropicToolsValues, AnthropicCodeExecutionTool, AnthropicComputerTool, @@ -1702,10 +1702,13 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig): def add_code_execution_tool( self, - messages: list[AllAnthropicMessageValues], + messages: list[AllAnthropicPassThroughMessageValues], tools: list[AllAnthropicToolsValues | dict], ) -> list[AllAnthropicToolsValues | dict]: - """if 'container_upload' in messages, add code_execution tool""" + """if 'container_upload' in messages, add code_execution tool + + Takes the pass-through union because the translator emits ``role: "system"`` + in ``messages`` for models that accept it; only ``content`` is read here.""" add_code_execution_tool = False for message in messages: message_content = message.get("content", None)