fix(anthropic): drop orphan tool_choice when tools array is empty (#25477)

This commit is contained in:
glaziermag 2026-04-10 11:27:22 -07:00
parent cae8613660
commit 5aa56f318c

View file

@ -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(