From 4d38915a03745be7affffd2b54604e6b48d227fe Mon Sep 17 00:00:00 2001 From: kimnamu Date: Sat, 13 Jun 2026 22:17:38 +0900 Subject: [PATCH] fix(bedrock): filter LiteLLM-internal params from invoke request bodies --- .../base_invoke_transformation.py | 6 +++++- .../test_base_invoke_transformation.py | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/litellm/llms/bedrock/chat/invoke_transformations/base_invoke_transformation.py b/litellm/llms/bedrock/chat/invoke_transformations/base_invoke_transformation.py index 8fc2375c224..8eaa798ddac 100644 --- a/litellm/llms/bedrock/chat/invoke_transformations/base_invoke_transformation.py +++ b/litellm/llms/bedrock/chat/invoke_transformations/base_invoke_transformation.py @@ -8,7 +8,10 @@ import httpx import litellm from litellm._logging import verbose_logger -from litellm.litellm_core_utils.core_helpers import map_finish_reason +from litellm.litellm_core_utils.core_helpers import ( + filter_internal_params, + map_finish_reason, +) from litellm.litellm_core_utils.logging_utils import track_llm_api_timing from litellm.litellm_core_utils.prompt_templates.factory import ( cohere_message_pt, @@ -168,6 +171,7 @@ class AmazonInvokeConfig(BaseConfig, BaseAWSLLM): for k, v in inference_params.items() if k not in self.aws_authentication_params } + inference_params = filter_internal_params(inference_params) request_data: dict = {} if provider == "cohere": if model.startswith("cohere.command-r"): diff --git a/tests/test_litellm/llms/bedrock/chat/invoke_transformations/test_base_invoke_transformation.py b/tests/test_litellm/llms/bedrock/chat/invoke_transformations/test_base_invoke_transformation.py index aff89f02ff2..8dcbb99c10b 100644 --- a/tests/test_litellm/llms/bedrock/chat/invoke_transformations/test_base_invoke_transformation.py +++ b/tests/test_litellm/llms/bedrock/chat/invoke_transformations/test_base_invoke_transformation.py @@ -39,3 +39,20 @@ def test_transform_request_drops_stream_chunk_size(config, model): ) assert "stream_chunk_size" not in json.dumps(request_body) + + +def test_transform_request_drops_internal_params(): + """LiteLLM-internal MCP params (e.g. skip_mcp_handler) are control flags used + inside LiteLLM and are not valid Bedrock inference parameters. Leaking them + into the provider request body makes Bedrock reject the request. The Converse + path already filters them via filter_internal_params; the invoke path must do + the same.""" + request_body = AmazonInvokeConfig().transform_request( + model="mistral.mistral-7b-instruct-v0:2", + messages=[{"role": "user", "content": "hi"}], + optional_params={"skip_mcp_handler": True, "max_tokens": 10}, + litellm_params={}, + headers={}, + ) + + assert "skip_mcp_handler" not in json.dumps(request_body)