Skip to content

Commit dcc604e

Browse files
committed
Python: fix(bedrock): base the prompt cleanup on the merged modelId
Signed-off-by: Manohar Paturi <[email protected]>
1 parent a47c3ef commit dcc604e

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎python/packages/bedrock/agent_framework_bedrock/_chat_client.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ def _prepare_options(
499499
# client_kwargs) join the request before the prompt-ARN cleanup so that
500500
# branch still strips fields Converse rejects, mirroring the other clients.
501501
run_options.update(kwargs)
502-
if ":prompt/" in model:
502+
if ":prompt/" in run_options["modelId"]:
503503
# A Prompt Management ARN takes these fields from the prompt, and Converse rejects requests that set them.
504504
if run_options["inferenceConfig"] == {"maxTokens": DEFAULT_MAX_TOKENS}:
505505
del run_options["inferenceConfig"] # only the client default, nothing the caller asked for

‎python/packages/bedrock/tests/test_bedrock_client.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,3 +1031,20 @@ def test_prepare_options_keeps_per_call_client_kwargs() -> None:
10311031

10321032
assert request["guardrailConfig"] == {"guardrailIdentifier": "gr-1", "guardrailVersion": "DRAFT"}
10331033
assert request["requestMetadata"] == {"channel": "test"}
1034+
1035+
1036+
def test_prepare_options_prompt_cleanup_uses_overridden_model_id() -> None:
1037+
"""A prompt ARN arriving through client kwargs must trigger the ARN cleanup (#9344)."""
1038+
client = _make_client()
1039+
messages = [Message(role="user", contents=[Content.from_text(text="hello")])]
1040+
1041+
request = client._prepare_options(
1042+
messages,
1043+
{},
1044+
modelId="arn:aws:bedrock:us-east-1:123456789012:prompt/PROMPT123",
1045+
)
1046+
1047+
assert ":prompt/" in request["modelId"]
1048+
assert "inferenceConfig" not in request, "prompt ARN requests must not carry inferenceConfig"
1049+
assert "system" not in request
1050+
assert "toolConfig" not in request

0 commit comments

Comments
 (0)