From 5aa56f318c09ef89407fbb01b2d7a745ce0c9910 Mon Sep 17 00:00:00 2001 From: glaziermag Date: Fri, 10 Apr 2026 11:27:22 -0700 Subject: [PATCH] fix(anthropic): drop orphan tool_choice when tools array is empty (#25477) --- litellm/llms/anthropic/chat/transformation.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/litellm/llms/anthropic/chat/transformation.py b/litellm/llms/anthropic/chat/transformation.py index 9a99f9efc82..dec77580175 100644 --- a/litellm/llms/anthropic/chat/transformation.py +++ b/litellm/llms/anthropic/chat/transformation.py @@ -1081,6 +1081,11 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig): non_default_params=non_default_params, optional_params=optional_params ) + # Anthropic requires tools to be specified if tool_choice is specified. + # If tools were stripped out (e.g. intercepted), we must also remove tool_choice. + if "tool_choice" in optional_params and not optional_params.get("tools"): + optional_params.pop("tool_choice", None) + return optional_params def _create_json_tool_call_for_response_format(