Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions python/packages/bedrock/tests/test_bedrock_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading