diff --git a/python/packages/bedrock/agent_framework_bedrock/_chat_client.py b/python/packages/bedrock/agent_framework_bedrock/_chat_client.py index 302e5e30981..6a3f07662cc 100644 --- a/python/packages/bedrock/agent_framework_bedrock/_chat_client.py +++ b/python/packages/bedrock/agent_framework_bedrock/_chat_client.py @@ -495,7 +495,11 @@ def _prepare_options( ): if (value := options.get(key)) is not None: run_options[key] = value - if ":prompt/" in model: + # Per-call client kwargs (for example Bedrock-native fields passed through + # client_kwargs) join the request before the prompt-ARN cleanup so that + # branch still strips fields Converse rejects, mirroring the other clients. + run_options.update(kwargs) + if ":prompt/" in run_options["modelId"]: # A Prompt Management ARN takes these fields from the prompt, and Converse rejects requests that set them. if run_options["inferenceConfig"] == {"maxTokens": DEFAULT_MAX_TOKENS}: del run_options["inferenceConfig"] # only the client default, nothing the caller asked for diff --git a/python/packages/bedrock/tests/test_bedrock_client.py b/python/packages/bedrock/tests/test_bedrock_client.py index 209cbaa9315..f00abfd6c49 100644 --- a/python/packages/bedrock/tests/test_bedrock_client.py +++ b/python/packages/bedrock/tests/test_bedrock_client.py @@ -1015,3 +1015,36 @@ def test_parse_message_contents_requires_tool_use_name() -> None: with pytest.raises(ChatClientInvalidResponseException, match="missing required tool name"): client._parse_message_contents([{"toolUse": {"toolUseId": "call-1"}}]) + + +def test_prepare_options_keeps_per_call_client_kwargs() -> None: + """Per-call client kwargs must land in the Converse request, not vanish (#9344).""" + client = _make_client() + messages = [Message(role="user", contents=[Content.from_text(text="hello")])] + + request = client._prepare_options( + messages, + {}, + guardrailConfig={"guardrailIdentifier": "gr-1", "guardrailVersion": "DRAFT"}, + requestMetadata={"channel": "test"}, + ) + + assert request["guardrailConfig"] == {"guardrailIdentifier": "gr-1", "guardrailVersion": "DRAFT"} + assert request["requestMetadata"] == {"channel": "test"} + + +def test_prepare_options_prompt_cleanup_uses_overridden_model_id() -> None: + """A prompt ARN arriving through client kwargs must trigger the ARN cleanup (#9344).""" + client = _make_client() + messages = [Message(role="user", contents=[Content.from_text(text="hello")])] + + request = client._prepare_options( + messages, + {}, + modelId="arn:aws:bedrock:us-east-1:123456789012:prompt/PROMPT123", + ) + + assert ":prompt/" in request["modelId"] + assert "inferenceConfig" not in request, "prompt ARN requests must not carry inferenceConfig" + assert "system" not in request + assert "toolConfig" not in request