Skip to content

fix(anthropic): handle tool_choice type 'none' in messages API - #24457

Merged
krrish-berri-2 merged 3 commits into
BerriAI:litellm_oss_staging_04_22_2026from
BillionClaw:clawoss/fix/24443-tool-choice-none
Apr 23, 2026
Merged

fix(anthropic): handle tool_choice type 'none' in messages API#24457
krrish-berri-2 merged 3 commits into
BerriAI:litellm_oss_staging_04_22_2026from
BillionClaw:clawoss/fix/24443-tool-choice-none

Conversation

@BillionClaw

Copy link
Copy Markdown
Contributor

Fixes #24443.

The Anthropic /v1/messages API accepts tool_choice={"type": "none"} to explicitly disable tool use. The translation layer in LiteLLMAnthropicMessagesAdapter.translate_anthropic_tool_choice_to_openai() was missing a handler for this case, causing it to fall through to a ValueError: Incompatible tool choice param submitted - {'type': 'none'}.

OpenAI's ChatCompletionToolChoiceValues accepts "none", so the fix is to add a branch that maps {"type": "none"}"none".

Added a regression test in the existing test file.

@vercel

vercel Bot commented Mar 23, 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 23, 2026 11:42pm

Request Review

@greptile-apps

greptile-apps Bot commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Adds handling for tool_choice={"type": "none"} in translate_anthropic_tool_choice_to_openai, mapping it to the OpenAI string "none" instead of raising a ValueError. The fix is minimal and correct — "none" is already declared as a valid literal in the AnthropicMessagesToolChoice TypedDict, and the new branch sits naturally alongside the existing "auto", "any", and "tool" branches.

Confidence Score: 5/5

Safe to merge — minimal, targeted bugfix with a regression test and no side effects.

The change is a single two-line addition that fills a gap already expressed in the existing TypedDict. No existing behaviour is altered, no mocks are weakened, and the new test exercises exactly the fixed path.

No files require special attention.

Important Files Changed

Filename Overview
litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py Added elif tool_choice["type"] == "none": return "none" branch to translate_anthropic_tool_choice_to_openai; correctly fills the missing case already typed in AnthropicMessagesToolChoice.
tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.py Adds test_translate_anthropic_tool_choice_none regression test; existing test reformatted cosmetically (no logic change).

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["translate_anthropic_tool_choice_to_openai(tool_choice)"] --> B{tool_choice type?}
    B -->|"any"| C["return 'required'"]
    B -->|"auto"| D["return 'auto'"]
    B -->|"tool"| E["truncate name\nreturn ChatCompletionToolChoiceObjectParam"]
    B -->|"none"| F["return 'none' ✅ NEW"]
    B -->|other| G["raise ValueError"]
Loading

Reviews (2): Last reviewed commit: "Merge branch 'litellm_oss_staging_04_22_..." | Re-trigger Greptile

@codspeed-hq

codspeed-hq Bot commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 16 untouched benchmarks


Comparing BillionClaw:clawoss/fix/24443-tool-choice-none (b3e5dd3) with main (63425b4)

Open in CodSpeed

@BillionClaw

Copy link
Copy Markdown
Contributor Author

This is BillionClaw. Happy to discuss the approach or make adjustments to the fix.

@lgx0319

lgx0319 commented Apr 15, 2026

Copy link
Copy Markdown

Friendly bump -- this PR has been open for a while. Happy to make any changes if needed, or close it if no longer relevant.

@krrish-berri-2
krrish-berri-2 changed the base branch from main to litellm_oss_staging_04_22_2026 April 23, 2026 02:35
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ BillionClaw
❌ krrish-berri-2
You have signed the CLA already but the status is still pending? Let us recheck it.

@krrish-berri-2
krrish-berri-2 merged commit 9479318 into BerriAI:litellm_oss_staging_04_22_2026 Apr 23, 2026
29 of 31 checks passed
@codecov

codecov Bot commented Apr 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@gitguardian

gitguardian Bot commented Apr 23, 2026

Copy link
Copy Markdown

⚠️ GitGuardian has uncovered 2 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

Since your pull request originates from a forked repository, GitGuardian is not able to associate the secrets uncovered with secret incidents on your GitGuardian dashboard.
Skipping this check run and merging your pull request will create secret incidents on your GitGuardian dashboard.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
29203053 Triggered Generic Password f7bb810 .circleci/config.yml View secret
29375658 Triggered JSON Web Token f7bb810 tests/test_litellm/proxy/auth/test_handle_jwt.py View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
…AI#24457)

* fix(anthropic): handle tool_choice type 'none' in messages API

* test(anthropic): add regression test for tool_choice type 'none'

---------

Co-authored-by: BillionClaw <267901332+BillionClaw@users.noreply.github.com>
Co-authored-by: Krrish Dholakia <krrish+github@berri.ai>
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

4 participants