fix(anthropic): handle tool_choice type 'none' in messages API - #24457
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryAdds handling for Confidence Score: 5/5Safe 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.
|
| 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"]
Reviews (2): Last reviewed commit: "Merge branch 'litellm_oss_staging_04_22_..." | Re-trigger Greptile
|
This is BillionClaw. Happy to discuss the approach or make adjustments to the fix. |
|
Friendly bump -- this PR has been open for a while. Happy to make any changes if needed, or close it if no longer relevant. |
|
|
9479318
into
BerriAI:litellm_oss_staging_04_22_2026
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
| 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
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secrets safely. Learn here the best practices.
- Revoke and rotate these secrets.
- 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
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 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.
…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>
Fixes #24443.
The Anthropic /v1/messages API accepts
tool_choice={"type": "none"}to explicitly disable tool use. The translation layer inLiteLLMAnthropicMessagesAdapter.translate_anthropic_tool_choice_to_openai()was missing a handler for this case, causing it to fall through to aValueError: 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.