fix: address Greptile review - remove redundant check, use defensive copy

This commit is contained in:
jawad-khan 2026-03-17 15:11:37 +05:00
parent 9cf8cf6f39
commit 8c3ffd9565
3 changed files with 5 additions and 6 deletions

View file

@ -1300,10 +1300,12 @@ class AmazonConverseConfig(BaseConfig):
continue
filtered_tools.append(tool)
# Defensive copy so we don't mutate caller data (router fallback/retry may reuse optional_params).
# Strip custom field from tools before sending to Bedrock Converse.
# Claude Code sends custom: {eager_input_streaming: true} etc. which Anthropic
# accepts but Bedrock rejects for some models (e.g. Haiku 4.5) with
# "Extra inputs are not permitted". Ref: https://github.com/BerriAI/litellm/issues/23825
filtered_tools = [copy.deepcopy(t) for t in filtered_tools]
strip_custom_from_tools_list(filtered_tools)
# Only separate tools if computer use tools are actually present

View file

@ -62,10 +62,7 @@ def remove_custom_field_from_tools(request_body: dict) -> None:
Ref: https://github.com/BerriAI/litellm/issues/22847
"""
tools = request_body.get("tools")
if not tools or not isinstance(tools, list):
return
strip_custom_from_tools_list(tools)
strip_custom_from_tools_list(request_body.get("tools"))
def strip_custom_from_tools_list(tools: list) -> None:

View file

@ -354,8 +354,8 @@ def test_process_tools_and_beta_strips_custom_field():
assert len(bedrock_tools) == 1
assert "toolSpec" in bedrock_tools[0]
assert bedrock_tools[0]["toolSpec"]["name"] == "get_weather"
# Original tools list should have been modified in-place (custom stripped)
assert "custom" not in tools_with_custom[0]
# Caller data should not be mutated (defensive copy used for router fallback safety)
assert "custom" in tools_with_custom[0]
def test_transform_request_helper_includes_anthropic_beta_and_tools():