Skip to content

fix(anthropic): inject dummy tool without modify_params - #27620

Merged
mateo-berri merged 2 commits into
litellm_internal_stagingfrom
litellm_anthropic_dummy_tool_default
May 11, 2026
Merged

fix(anthropic): inject dummy tool without modify_params#27620
mateo-berri merged 2 commits into
litellm_internal_stagingfrom
litellm_anthropic_dummy_tool_default

Conversation

@Sameerlite

@Sameerlite Sameerlite commented May 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Anthropic rejects requests that include tool-use / tool-result turns when the tools array is missing. LiteLLM now always injects the minimal dummy tool in AnthropicConfig.transform_request when messages contain tool-call blocks and no tools param, without requiring litellm.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 -v
  • Updated test_parallel_function_call_anthropic_error_msg: Bedrock Converse still raises UnsupportedParamsError without modify_params; direct Anthropic no longer does.

Notes

  • Bedrock Converse (converse_transformation.py) is unchanged; dummy tool there remains behind modify_params.
  • Repo-wide black --check reports pre-existing drift in other files; the three touched files pass black --check.
image

Note

Medium Risk
Changes request-shaping for Anthropic tool-calling by always injecting a dummy tools entry 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 the tools array by always injecting a minimal dummy tool in AnthropicConfig.transform_request, independent of litellm.modify_params.

Updates tests to reflect the new behavior: direct Anthropic no longer raises UnsupportedParamsError in this scenario, while Bedrock Converse is explicitly asserted to still require modify_params; adds a unit test ensuring transform_request injects dummy_tool when needed.

Reviewed by Cursor Bugbot for commit cb7f60e. Bugbot is set up for automated code reviews on this repo. 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>
@codecov

codecov Bot commented May 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@greptile-apps

greptile-apps Bot commented May 11, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR removes the litellm.modify_params gate from dummy-tool injection in AnthropicConfig.transform_request, so LiteLLM now always injects a minimal dummy tool when messages contain tool-call blocks but no tools array is supplied — without requiring any user-side configuration.

  • transformation.py: The if litellm.modify_params / else raise UnsupportedParamsError branch is replaced by an unconditional optional_params[\"tools\"], _ = self._map_tools(add_dummy_tool(...)) call. Because all Anthropic-shaped provider configs (AmazonAnthropicClaudeConfig, VertexAIAnthropicConfig, AzureAnthropicConfig) delegate to this method, the change silently affects Bedrock Invoke, Vertex AI, and Azure Anthropic in addition to direct Anthropic — Bedrock Converse (converse_transformation.py) is intentionally left unchanged.
  • test_anthropic_chat_transformation.py: A new pure-unit test exercises the injection path with modify_params=False, confirms dummy_tool appears in the result, and correctly restores global state in a finally block.
  • test_function_calling.py: The parametrised live test is updated so only the Bedrock Converse case still expects UnsupportedParamsError; the Anthropic path now exercises a live API call with InternalServerError/RateLimitError errors silently swallowed.

Confidence Score: 4/5

The 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.

Important Files Changed

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

Comment thread tests/local_testing/test_function_calling.py
@Sameerlite

Copy link
Copy Markdown
Contributor Author

@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

@greptile-apps

greptile-apps Bot commented May 11, 2026

Copy link
Copy Markdown
Contributor

That's a completely valid point and the PR's approach is correct. The modify_params flag is a library-level global state that CLIs and frameworks using litellm as a dependency can't reasonably be expected to set — requiring it creates a broken integration for tools like OpenHands, Aider, etc.

The remaining concern from my original comment is specifically about the integration test coverage, not the behavioral change itself. Since test_parallel_function_call_anthropic_error_msg catches InternalServerError and RateLimitError silently, if CI lacks Anthropic credentials the new expect_unsupported_params_error=False path doesn't actually verify the dummy tool injection worked end-to-end. However, the dedicated unit test test_transform_request_injects_dummy_tool_without_tools_param in test_anthropic_chat_transformation.py covers this at the transformation layer without any network dependency — that's the right place for this assertion, and it's solid.

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.

@Sameerlite

Copy link
Copy Markdown
Contributor Author

@greptile-apps re review

@Sameerlite

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment

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.

✅ 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.

@mateo-berri mateo-berri left a comment

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.

LGTM; thanks!

@mateo-berri
mateo-berri merged commit 4c1d91d into litellm_internal_staging May 11, 2026
117 checks passed
@mateo-berri
mateo-berri deleted the litellm_anthropic_dummy_tool_default branch May 11, 2026 16:50
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
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>
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.

3 participants