fix(anthropic): allow tool_choice type 'none' in messages API - #24465
fix(anthropic): allow tool_choice type 'none' in messages API#24465BillionClaw wants to merge 1 commit into
Conversation
The Anthropic /v1/messages API supports tool_choice={"type":"none"}
to disable tool use. LiteLLM was rejecting this with a 500 error.
Added 'none' as a valid tool_choice variant. Fixes BerriAI#24443.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR fixes a bug where passing
Confidence Score: 4/5
|
| Filename | Overview |
|---|---|
| litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py | Adds handling for tool_choice={"type": "none"} in translate_anthropic_tool_choice_to_openai; the remaining ~99% of the diff is pure code reformatting (collapsing multi-line expressions onto single lines) with no logic changes. The fix itself is correct — "none" is already a valid value in both AnthropicMessagesToolChoice and ChatCompletionToolChoiceValues. No test was added to verify the new branch. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["Incoming Anthropic Messages API Request\n(tool_choice param)"] --> B{"tool_choice type?"}
B -->|"any"| C["return 'required'"]
B -->|"auto"| D["return 'auto'"]
B -->|"tool"| E["Build ChatCompletionToolChoiceObjectParam\nwith truncated name"]
B -->|"none" ✅ NEW| F["return 'none'"]
B -->|"other"| G["raise ValueError\n(HTTP 500)"]
C --> H["OpenAI-format request"]
D --> H
E --> H
F --> H
Reviews (1): Last reviewed commit: "fix(anthropic): allow tool_choice type '..." | Re-trigger Greptile
| elif tool_choice["type"] == "none": | ||
| return "none" |
There was a problem hiding this comment.
The PR claims to fix an issue where tool_choice={"type": "none"} caused an HTTP 500, but no test was added to tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.py to verify this behavior. The existing test file has extensive coverage for translate_anthropic_tool_choice_to_openai for the auto, any, and tool branches, but the new none branch is untested.
A minimal test should be added:
def test_translate_tool_choice_none():
adapter = LiteLLMAnthropicMessagesAdapter()
result = adapter.translate_anthropic_tool_choice_to_openai({"type": "none"})
assert result == "none"Without this, a future refactor could silently reintroduce the regression.
Rule Used: What: Ensure that any PR claiming to fix an issue ... (source)
|
Closing as duplicate. Correct PR with test coverage is #24457. |
Fixes #24443. Anthropic messages API supports tool_choice={"type":"none"} to disable tool use. LiteLLM was rejecting this with HTTP 500. Added 'none' as a valid tool_choice variant.