fix(anthropic): inject dummy tool without modify_params - #27620
Conversation
Anthropic rejects tool_use/tool_result when tools is omitted. Always map and attach the dummy tool in transform_request so CLIs work without litellm.modify_params. - Add unit test for transform_request dummy tool with modify_params off - Adjust parallel function calling integration expectations: Bedrock Converse still requires modify_params for this path Co-authored-by: Cursor <cursoragent@cursor.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Greptile SummaryThis PR removes the
Confidence Score: 4/5The change is safe to merge for users who want silent dummy-tool injection, but silently alters behaviour for every caller using AnthropicConfig.transform_request — including Bedrock Invoke, Vertex AI, and Azure Anthropic — who previously received UnsupportedParamsError without modify_params. The core logic change is small and well-tested by the new unit test. However, the modify_params gate is removed unconditionally, which changes the observable contract for all Anthropic-shaped providers that inherit from AnthropicConfig. Callers that previously relied on the error signal to detect misconfigured tool-history messages will now receive silently transformed requests instead, with no opt-out mechanism. litellm/llms/anthropic/chat/transformation.py — the unconditional injection now affects every Anthropic-backed provider that delegates to this method, not only direct Anthropic.
|
| Filename | Overview |
|---|---|
| litellm/llms/anthropic/chat/transformation.py | Removed modify_params gate from dummy-tool injection; the tool is now unconditionally added whenever messages contain tool-call blocks but tools is absent. Affects all subclasses (Bedrock Invoke, Vertex AI, Azure Anthropic) that delegate to this method. |
| tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py | New pure-unit test test_transform_request_injects_dummy_tool_without_tools_param correctly validates the unconditional injection path with no live network calls, restores global state in a finally block, and asserts dummy_tool is present in the result. |
| tests/local_testing/test_function_calling.py | Updated test_parallel_function_call_anthropic_error_msg to reflect new per-provider behaviour: Bedrock Converse still expects UnsupportedParamsError, direct Anthropic no longer does. The Anthropic no-error path now makes a live API call whose InternalServerError/RateLimitError exceptions are silently swallowed. |
Reviews (2): Last reviewed commit: "fix(anthropic): inject dummy tool withou..." | Re-trigger Greptile
|
@greptile-apps P1 can not be solved, as CLIs using litellm, can't provide the flag, hence it makes litellm integration with clis very bad. Hence this feat needs to come out of the flag |
|
That's a completely valid point and the PR's approach is correct. The The remaining concern from my original comment is specifically about the integration test coverage, not the behavioral change itself. Since The behavioral change is correct and the unit test provides reliable coverage. The integration test weakness is a pre-existing pattern in that file (relying on live API calls), not something introduced by this PR. The change is good to go. |
|
@greptile-apps re review |
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 1c48104. Configure here.
Anthropic rejects tool_use/tool_result when tools is omitted. Always map and attach the dummy tool in transform_request so CLIs work without litellm.modify_params. - Add unit test for transform_request dummy tool with modify_params off - Adjust parallel function calling integration expectations: Bedrock Converse still requires modify_params for this path Co-authored-by: Cursor <cursoragent@cursor.com>
Summary
Anthropic rejects requests that include tool-use / tool-result turns when the
toolsarray is missing. LiteLLM now always injects the minimal dummy tool inAnthropicConfig.transform_requestwhen messages contain tool-call blocks and notoolsparam, without requiringlitellm.modify_params.Fixes LIT-2983
Tests
poetry run pytest tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py::test_transform_request_injects_dummy_tool_without_tools_param -vtest_parallel_function_call_anthropic_error_msg: Bedrock Converse still raisesUnsupportedParamsErrorwithoutmodify_params; direct Anthropic no longer does.Notes
converse_transformation.py) is unchanged; dummy tool there remains behindmodify_params.black --checkreports pre-existing drift in other files; the three touched files passblack --check.Note
Medium Risk
Changes request-shaping for Anthropic tool-calling by always injecting a dummy
toolsentry when tool turns are present, which can affect how tool-enabled conversations are routed and validated across Anthropic-backed providers.Overview
Fixes Anthropic tool-calling requests that include
tool_use/tool history but omit thetoolsarray by always injecting a minimal dummy tool inAnthropicConfig.transform_request, independent oflitellm.modify_params.Updates tests to reflect the new behavior: direct Anthropic no longer raises
UnsupportedParamsErrorin this scenario, while Bedrock Converse is explicitly asserted to still requiremodify_params; adds a unit test ensuringtransform_requestinjectsdummy_toolwhen needed.Reviewed by Cursor Bugbot for commit cb7f60e. Bugbot is set up for automated code reviews on this repo. Configure here.