fix(bedrock): remove remove_custom_field_from_tools — Bedrock now supports custom.defer_loading natively#26143
fix(bedrock): remove remove_custom_field_from_tools — Bedrock now supports custom.defer_loading natively#26143Anai-Guo wants to merge 4 commits intoBerriAI:mainfrom
Conversation
Greptile SummaryThis PR removes the Confidence Score: 5/5Safe to merge — the change is a clean removal of a workaround that is no longer needed, with no logic altered beyond stripping the stripping. All findings are P2 (missing passthrough test for the new behavior). The core change is minimal, well-explained, and consistent across both Bedrock invoke paths. The deleted test was appropriate to delete since the function it covered is gone. The test file is the only file worth a second look — consider adding a test verifying
|
| Filename | Overview |
|---|---|
| litellm/llms/bedrock/common_utils.py | Removes the remove_custom_field_from_tools() function entirely; normalize_tool_input_schema_types_for_bedrock_invoke is correctly retained for the separate type: "custom" schema issue. |
| litellm/llms/bedrock/chat/invoke_transformations/anthropic_claude3_transformation.py | Removes import and call of remove_custom_field_from_tools; the remaining normalize_tool_input_schema_types_for_bedrock_invoke call is unaffected. |
| litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py | Removes import and call of remove_custom_field_from_tools; adjacent transformation steps (normalize_tool_input_schema_types_for_bedrock_invoke, ensure_bedrock_anthropic_messages_tool_names) are correctly preserved. |
| tests/test_litellm/llms/bedrock/messages/invoke_transformations/test_anthropic_claude3_transformation.py | Removes the test_remove_custom_field_from_tools test (appropriate since the function is gone), but no new test is added to verify custom.defer_loading is preserved through the transformation pipeline. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["Incoming request\n(tools with custom: {defer_loading: true})"] --> B[AmazonAnthropicClaudeMessagesConfig\n.transform_request]
A --> C[AmazonAnthropicClaudeConfig\n.transform_request]
B --> D["~~remove_custom_field_from_tools()~~\n(REMOVED)"]
C --> E["~~remove_custom_field_from_tools()~~\n(REMOVED)"]
D --> F[normalize_tool_input_schema_types_for_bedrock_invoke\ntype:custom → object in input_schema]
E --> F
F --> G[Bedrock Invoke API\nnow accepts custom field natively]
Reviews (1): Last reviewed commit: "test(bedrock): remove test_remove_custom..." | Re-trigger Greptile
| assert request4["tools"] is None | ||
|
|
||
|
|
||
| def test_normalize_tool_input_schema_types_for_bedrock_invoke(): |
There was a problem hiding this comment.
Missing test for preserved
custom field passthrough
The deleted test verified that custom fields were stripped; now that the stripping is removed, there is no corresponding test verifying that custom: {defer_loading: true} is actually preserved (not dropped) in the final Bedrock request body. A regression here (e.g., a future developer re-adding the strip or an upstream transform clearing it) would go undetected. Consider adding a test asserting the custom field survives the full transformation pipeline alongside test_normalize_tool_input_schema_types_for_bedrock_invoke.
Summary
Removes
remove_custom_field_from_tools()and all its call sites.This function was added in #22861 (fixing #22847) to strip the
custom: {defer_loading: true}field from tool definitions before forwarding to Bedrock, because Bedrock was rejecting it with"Extra inputs are not permitted".Bedrock has since been updated and now accepts
custom.defer_loadingnatively. When using Claude Code directly against Bedrock (without LiteLLM), Tool Search works correctly. But routing through LiteLLM → Bedrock caused the field to be stripped, defeating the feature and loading every tool definition into context — adding ~20k+ extra input tokens per request for a typical MCP setup.Changes
litellm/llms/bedrock/common_utils.py: Removeremove_custom_field_from_tools()functionlitellm/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py: Remove import + calllitellm/llms/bedrock/chat/invoke_transformations/anthropic_claude3_transformation.py: Remove import + calltests/…/test_anthropic_claude3_transformation.py: Removetest_remove_custom_field_from_toolstestNote:
normalize_json_schema_custom_types_to_object()andnormalize_tool_input_schema_types_for_bedrock_invoke()are intentionally kept — they handletype: "custom"in JSON schemas, which is a separate issue that Bedrock still does not accept.Test plan
defer_loadingis preserved in tool definitionsFixes #26113
🤖 Generated with Claude Code