Skip to content

fix(bedrock-invoke): filter internal params from request body - #30400

Closed
michaelxer wants to merge 1 commit into
BerriAI:litellm_internal_stagingfrom
michaelxer:fix/bedrock-invoke-filter-internal-params
Closed

michaelxer wants to merge 1 commit into
BerriAI:litellm_internal_stagingfrom
michaelxer:fix/bedrock-invoke-filter-internal-params

Conversation

@michaelxer

Copy link
Copy Markdown
Contributor

Problem

The Bedrock invoke transform leaks LiteLLM-internal optional_params into the provider request body. After filtering out AWS-auth keys, the remaining inference_params are splatted directly into the request:

inference_params = {k: v for k, v in inference_params.items()
                    if k not in self.aws_authentication_params}
...
request_data = {"prompt": prompt, **inference_params}   # internal knobs leak through

Internal control flags like skip_mcp_handler, _skip_mcp_handler, and mcp_handler_context are not valid Bedrock inference parameters. Leaking them into the body can cause Bedrock to reject the request.

Why this is a gap in an existing pattern

The sibling Converse path already guards against exactly this:

# litellm/llms/bedrock/chat/converse_transformation.py
additional_request_params = filter_internal_params(additional_request_params)

The invoke path never calls filter_internal_params — it relies on pop()-ing each internal key one at a time (which is how stream_chunk_size leaked in #30240). Routing the invoke path through the same shared helper closes this class of bugs in one place.

Fix

Added filter_internal_params(inference_params) after the aws_authentication_params exclusion in transform_request. This is the same one-line pattern the Converse path already uses.

Also added a regression test covering both Cohere and AI21 provider paths, verifying that internal params are stripped while legitimate params like max_tokens are preserved.

Testing

tests/llm_translation/test_unit_test_bedrock_invoke.py — 11/11 passed

Closes #30371

The Bedrock invoke path leaks LiteLLM-internal optional_params (e.g.
skip_mcp_handler, _skip_mcp_handler, mcp_handler_context) into the
provider request body. The sibling Converse path already guards against
this via filter_internal_params().

Add the same filter to the invoke transform_request after the
aws_authentication_params exclusion, closing the gap in one place.

Includes a regression test covering both Cohere and AI21 provider paths.
@codecov

codecov Bot commented Jun 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@michaelxer
michaelxer marked this pull request as ready for review June 14, 2026 07:40
@greptile-apps

greptile-apps Bot commented Jun 14, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a bug in the Bedrock invoke transform path where LiteLLM-internal parameters (skip_mcp_handler, _skip_mcp_handler, mcp_handler_context) were leaking into the provider request body and could cause Bedrock to reject requests. It applies the same filter_internal_params one-liner already used by the Converse path.

  • Adds filter_internal_params(inference_params) after the aws_authentication_params exclusion in AmazonInvokeConfig.transform_request, covering the cohere, ai21, mistral, amazon, and meta/llama/deepseek_r1 branches.
  • Adds a new regression test in test_unit_test_bedrock_invoke.py that checks both the Cohere and AI21 provider paths, asserting internal params are stripped while legitimate params like max_tokens are preserved.

Confidence Score: 4/5

The core fix is correct and well-tested; the delegate sub-paths (anthropic, nova, twelvelabs, openai) still forward raw optional_params to their own transform classes, which may warrant a follow-up.

The one-line change is straightforward and mirrors the already-working Converse path. The new tests are additive and cover both a positive and negative case. The only concern is that the four delegate branches (anthropic, nova, twelvelabs, openai) bypass inference_params entirely and pass the original optional_params to sub-transformers, so whether those sub-transformers filter internal params themselves is not verified here. That gap is pre-existing and out of scope for this fix, but it means the protection is incomplete across all invoke sub-paths.

The delegate paths in base_invoke_transformation.py (anthropic, nova, twelvelabs, openai branches) pass unfiltered optional_params to their respective sub-transformers and deserve a follow-up check.

Important Files Changed

Filename Overview
litellm/llms/bedrock/chat/invoke_transformations/base_invoke_transformation.py Adds filter_internal_params(inference_params) after the aws-auth-key exclusion, fixing the MCP param leak for cohere/ai21/mistral/amazon/llama branches; delegate paths (anthropic, nova, twelvelabs, openai) still receive unfiltered optional_params.
tests/llm_translation/test_unit_test_bedrock_invoke.py New regression test covering Cohere and AI21 provider paths; verifies internal params are stripped and legitimate params (max_tokens) are preserved. No existing tests were modified.

Comments Outside Diff (1)

  1. litellm/llms/bedrock/chat/invoke_transformations/base_invoke_transformation.py, line 194-253 (link)

    P2 Delegate paths bypass the new filter

    The anthropic, nova, twelvelabs, and openai provider branches return early (lines 194–253) by passing the raw, unfiltered optional_params directly to their delegate transform_request methods — so filter_internal_params on line 174 never gets a chance to protect those paths. If the delegate classes (e.g. AmazonAnthropicClaudeConfig, AmazonInvokeNovaConfig) don't call filter_internal_params themselves, internal params like skip_mcp_handler will still leak into those request bodies. This is a pre-existing gap not introduced by this PR, but the fix as written only closes it for the cohere, ai21, mistral, amazon, and meta/llama branches.

Reviews (1): Last reviewed commit: "fix(bedrock-invoke): filter internal par..." | Re-trigger Greptile

for k, v in inference_params.items()
if k not in self.aws_authentication_params
}
inference_params = filter_internal_params(inference_params)

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.

Medium: Internal params can leak on delegated providers

A caller using Bedrock Invoke models that take the delegated branches (anthropic, nova, twelvelabs, or imported openai) can send skip_mcp_handler or mcp_handler_context to the provider because those branches pass the original optional_params, not this filtered copy. Filter the local optional_params before delegation, or pass the filtered params into those transformers.

Suggested change
inference_params = filter_internal_params(inference_params)
inference_params = filter_internal_params(inference_params)
optional_params = filter_internal_params(optional_params)

@veria-ai

veria-ai Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

PR overview

This pull request updates Bedrock Invoke chat request transformation to filter internal LiteLLM parameters from request bodies before provider calls. The touched code is in the Bedrock invoke transformation path, including delegated provider handling for model-specific transformers.

There is still one open issue: delegated Bedrock Invoke branches can continue passing the original unfiltered optional parameters to downstream provider transformers. That means internal parameters such as MCP handler flags or context may still be sent to external providers for certain model paths. No issues have been addressed yet, so the PR does not currently fully achieve its intended parameter-filtering protection.

Open issues (1)

Fixed/addressed: 0 · PR risk: 5/10

@Sameerlite

Copy link
Copy Markdown
Contributor

Thanks for the fix and the test output! Two things to address:

  • CI is failing on proxy-infra / Run tests — could you investigate whether that failure is related to this change?
  • Greptile scored 4/5 noting that some delegate branches may still pass unfiltered optional params. Could you check those paths?

@michaelxer

Copy link
Copy Markdown
Contributor Author

Thanks for the review! Looked into the proxy-infra / Run tests failure:

The single failing test is test_deprecated_key_grace_period_cache_hit_path — an httpx.ConnectError: All connection attempts failed (connection refused to a local proxy during E2E key rotation). This is a CI infrastructure flake, not related to our Bedrock body filter change. Our PR only touches base_invoke_transformation.py and adds a test for it — nothing in the key rotation or proxy server path.

3248 of 3249 tests pass. The one failure is a network connectivity issue in the test runner environment.

Would you like me to re-run CI to get a clean check, or is this good to proceed?

@michaelxer

Copy link
Copy Markdown
Contributor Author

@Sameerlite Good point on the Greptile flag. The delegate paths (anthropic, nova, twelvelabs, openai) pass raw optional_params to their sub-transformers — that's a pre-existing gap, not introduced by this PR. The sub-transformers may already handle filtering internally, but I'll verify each delegate class and open a follow-up if any of them leak the same internal params.

For now this PR fixes the confirmed leak in the cohere/ai21/mistral/amazon/llama paths, which is where the original issue was reported.

@michaelxer

Copy link
Copy Markdown
Contributor Author

Closing as this has been open for over a week with only a pre-existing proxy-infra test failure. The fix is straightforward if the test environment stabilizes — happy to reopen if needed.

@michaelxer michaelxer closed this Jun 21, 2026
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.

[Bug]: Bedrock invoke path leaks LiteLLM-internal params into the request body (Converse already filters them)

2 participants