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 90a2692f68a..e0d8901e484 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 @@ from pydantic import TypeAdapter, ValidationError 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, @@ -195,6 +198,7 @@ class AmazonInvokeConfig(BaseConfig, BaseAWSLLM): ) inference_params = copy.deepcopy(optional_params) inference_params = {k: v 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 96a2fa6ec67..0ff6b6edaa8 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,6 +39,23 @@ 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) + + def test_validate_environment_maps_guardrail_config_to_invoke_headers(): """The InvokeModel API takes the guardrail identifier/version/trace as X-Amzn-Bedrock-* request headers, unlike Converse which takes them in the