Skip to content

fix(anthropic): allow tool_choice type 'none' in messages API - #24465

Closed
BillionClaw wants to merge 1 commit into
BerriAI:mainfrom
BillionClaw:clawoss/fix/tool-choice-none
Closed

fix(anthropic): allow tool_choice type 'none' in messages API#24465
BillionClaw wants to merge 1 commit into
BerriAI:mainfrom
BillionClaw:clawoss/fix/tool-choice-none

Conversation

@BillionClaw

Copy link
Copy Markdown
Contributor

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.

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.
@vercel

vercel Bot commented Mar 24, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Mar 24, 2026 3:42am

Request Review

@codspeed-hq

codspeed-hq Bot commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 16 untouched benchmarks


Comparing BillionClaw:clawoss/fix/tool-choice-none (acb238f) with main (3292d02)

Open in CodSpeed

@greptile-apps

greptile-apps Bot commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a bug where passing tool_choice={"type": "none"} to the Anthropic Messages API pass-through endpoint caused an HTTP 500 error. The fix adds a single elif branch (elif tool_choice["type"] == "none": return "none") to translate_anthropic_tool_choice_to_openai in LiteLLMAnthropicMessagesAdapter. The core change is correct: "none" is already a valid literal in AnthropicMessagesToolChoice and a valid value in ChatCompletionToolChoiceValues, so no type changes were needed.

  • Core fix (1 line): Adds elif tool_choice["type"] == "none": return "none" to translate_anthropic_tool_choice_to_openai
  • Reformatting (~99% of the diff): The PR collapses many multi-line expressions onto single lines throughout the file — no logic is changed, but this dramatically increases diff noise and makes the actual fix harder to spot in review
  • No test added: The fix has no corresponding test in the existing test suite for this adapter; per team standards, fixes should include evidence of resolution

Confidence Score: 4/5

  • Safe to merge — the fix is correct and targeted, with no risk of regressions to existing tool_choice types.
  • The one-line logic fix is correct: "none" is already a valid value in both the Anthropic type definition and the OpenAI translation target. The large reformatting diff adds noise but doesn't change any behavior. The only gap is the absence of a regression test for the new branch, which lowers confidence slightly.
  • No files require special attention beyond the missing test for the tool_choice={"type": "none"} branch.

Important Files Changed

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
Loading

Reviews (1): Last reviewed commit: "fix(anthropic): allow tool_choice type '..." | Re-trigger Greptile

Comment on lines +670 to +671
elif tool_choice["type"] == "none":
return "none"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 No test coverage for the fix

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)

@BillionClaw

Copy link
Copy Markdown
Contributor Author

Closing as duplicate. Correct PR with test coverage is #24457.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: tool_choice of none not working with messages API

1 participant