Skip to content

Example of Bedrock Converse API with Managed Prompt Variant

0

From https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_Converse.html

If you use a prompt created through Prompt management, specify the ARN of the prompt version. For more information, see Test a prompt using Prompt management.

From referenced https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-management-test.html

You can test your prompt in the following ways: To run inference on the prompt, send an InvokeModel InvokeModelWithResponseStream, Converse, or ConverseStream request with an Amazon Bedrock runtime endpoint and specify the ARN of the prompt in the modelId parameter. Note The following restrictions apply when you use a Prompt management prompt with Converse or ConverseStream:

  • You can't include the additionalModelRequestFields, inferenceConfig, system, or toolConfig fields.
  • If you include the messages field, the messages are appended after the messages defined in the prompt.
  • If you include the guardrailConfig field, the guardrail is applied to the entire prompt. If you include guardContent blocks in the ContentBlock field, the guardrail will only be applied to those blocks.

There is mention of utilizing a Prompt created in Prompt Management with the Converse API, but there is no mention of how to utilize a particular variant of the specified Managed Prompt. How is a variant selected when a Managed Prompt has multiple variants?

1 Answer
0

When using a managed prompt with multiple variants in the Amazon Bedrock Converse API, you need to specify the exact ARN of the prompt version you want to use, which includes the variant information.

The ARN structure for a prompt version includes the variant identifier. When you create a prompt in Prompt Management, each variant gets its own unique ARN. To use a specific variant, you would use that variant's complete ARN as the modelId parameter in your Converse API call.

For example, in Python using boto3:

import boto3

bedrock = boto3.client('bedrock-runtime')

response = bedrock.converse(
modelId='arn:aws:bedrock:region:account-id:prompt/prompt-name/version/variant-id',
promptVariables={
"variable_name": {"text": "variable_value"},
"another_variable": {"text": "another_value"}
}
)

Or using the AWS CLI:

aws bedrock-runtime converse \
--model-id arn:aws:bedrock:region:account-id:prompt/prompt-name/version/variant-id \
--prompt-variables '{"variable_name":{"text":"variable_value"},"another_variable":{"text":"another_value"}}'

The key is that you're not selecting a variant separately - the variant is already embedded in the ARN you use as the modelId. Each variant has its own distinct ARN that you would use to invoke that specific variant.
Sources
Amazon Bedrock Prompt Management is now available in GA | AWS Machine Learning Blog
Using Bedrock invokeModel API with prompt created in prompt management | AWS re:Post

answered 9 months ago

  • the specified arn:aws:bedrock:region:account-id:prompt/prompt-name/version/variant-id format looks suspicious as prompt arns do not even utilize the specified name, but a generated 10 character alphanumeric string instead.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.