← AI Practitioner study path

Practice in your account · 25 min

A reusable prompt with Amazon Bedrock Prompt Management

In this lab you will save a prompt with two variables in Amazon Bedrock Prompt Management, compare two variants with the same values, create two versions and call the first one from CloudShell.

Amazon Bedrock Prompt Management is the part of Amazon Bedrock that stores a outside an application's code, together with the model and the parameters it is used with. The code is the text with the instructions that make up the application, and the parameters are model settings, such as the temperature, which decides how varied the responses are. This lab is for someone who has already made their first call to a model with converse and wants to see how an application reuses the same prompt without copying it into every call. For example, an online store that uses a model to write the description of each product always uses the same prompt and only changes the product name.

When you call a model with converse, you write the whole prompt in every call. If an application works that way, the prompt text, the model and the temperature are copied into its code, so changing a single word of the prompt forces you to the application again. Prompt Management solves that with two pieces: variables, which the application fills in on each call, and versions, which stay fixed even if you keep editing the prompt's draft. For example, if the store wants shorter descriptions, it changes the prompt saved in Bedrock and doesn't touch its application's code.

Variables, variants and versions of a prompt

A saved prompt has variables, which are filled in on each call, and it can be tested in variants with the same values. The variant you choose is fixed in versions, which are snapshots of the prompt, and the application calls one of those versions. A snapshot is a copy of the prompt as it was at one moment, which no longer changes. For example, the store tests the prompt with two models, keeps the one that writes better and saves that combination as version 1.

Before you start

This lab uses the us-east-2 Region, where Prompt Management is available just as it is in us-east-1 and other Regions. If you have never opened Bedrock, first do Your first call to a model in Amazon Bedrock, where you open CloudShell for the first time.

You will use two models: Amazon Nova Lite for variant A and Mistral Large 3 for variant B. Both are invoked within us-east-2, which is what a new experience account requires. In a full account you can use any text model compatible with the Converse , which is the way of calling Bedrock that the converse command uses. For example, in that account you could also try a model that in us-east-2 can only be called from other Regions.

Create the prompt with two variables

  1. Open the Amazon Bedrock console (https://console.aws.amazon.com/bedrock). In the left panel choose Prompt management and then Create prompt.
  2. Enter the name descripcion-producto, leave encryption with the AWS managed key and choose Create prompt. The console takes you to the prompt builder.
  3. In the User message box, enter:

Escribe una descripción de {{producto}} en 50 palabras, en tono {{tono}}.

Each word in double curly braces is a variable, and it appears in the Test variables section. 4. In Configurations, choose Amazon Nova Lite as the model and, in Inference parameters, set the temperature to 0.2. 5. In Test variables, enter audífonos inalámbricos for producto and formal for tono. Choose Run in the test window and read the response.

Step 2 leaves with the key AWS manages for you, so you don't have to create or look after any key. The model and the temperature from step 4 are saved in the prompt's configuration, so the application doesn't have to send them. The values in Test variables, on the other hand, are temporary and only serve for testing in the , because the application sends its own values on each call. For example, you tested with wireless headphones, and the store's application will send a backpack, a lamp or any other product, each one in its own call.

True or false?

0 of 3
  1. The values you enter in Test variables are saved with the prompt.

  2. If I want the application to choose the tone, I mark it as {{tono}} in the message.

  3. To change the prompt's temperature I have to change the application's code.

Compare variants and create versions

A variant is another combination of model and parameters for the same prompt, and the console lets you compare up to three with the same test values. The variant you choose is saved as a draft, which is the copy of the prompt you can still edit, and each version you create from that draft stays fixed even if you keep editing it. For example, with the same headphones and the same tone, variant A uses Nova Lite with a low temperature and variant B uses Mistral Large 3 with a high temperature, and you decide which description reads better.

  1. Choose Compare variants and add a variant with the plus sign. In the new variant, choose Mistral Large 3 and temperature 0.8. Use the same test values and choose Run in each variant.
  2. Compare the two descriptions and choose Save as draft in the variant you prefer. That variant replaces the draft and the other one is deleted.
  3. Choose Create version. That is version 1.
  4. Go back to Edit in prompt builder, change "50 palabras" to "30 palabras", save the draft and choose Create version again. That is version 2.
  5. Open version 1 in the Versions section and check that it still says 50 palabras.

Version 1 keeps the 50 words because a version is a snapshot of the prompt at the moment you create it. That is why an application in points to a version, and the draft's changes only reach it when you create a new version and the application switches to it. For example, while someone at the store tries 30-word descriptions in the draft, customers keep seeing the 50-word ones from version 1.

What does your application use?

Your application in production calls version 1. Tomorrow someone edits the draft and leaves it half done. What happens to the application's responses?

How to know you're done

In the console, the details page for descripcion-producto shows the draft and two versions. To check it from CloudShell, the that opens inside the console, first look up the prompt's ID and ARN. The ID is the prompt's short code, and the ARN is its full name in AWS, which includes the Region and the account:

aws bedrock-agent list-prompts --region us-east-2 \
  --query "promptSummaries[?name=='descripcion-producto'].[name,id,arn]" --output table

With the ID that command returns, list the prompt's versions:

aws bedrock-agent list-prompts --region us-east-2 --prompt-identifier <ID> \
  --query "promptSummaries[].[name,version]" --output table

Finally, call version 1 the way your application would. Instead of the model ID you use the prompt's ARN, which is its full identifier in AWS, followed by its version, and you only send the values of the variables:

aws bedrock-runtime converse --region us-east-2 \
  --model-id "<ARN del prompt>:1" \
  --prompt-variables '{"producto":{"text":"una mochila para laptop"},"tono":{"text":"casual"}}' \
  --query "output.message.content[0].text" --output text

The response should have about 50 words, because version 1 is the one that says 50. This call doesn't include --messages or --inference-config because the saved prompt already has the message and the configuration. Also, when you call a Prompt Management prompt, the Converse API doesn't accept inferenceConfig. For example, if you wanted another temperature, you wouldn't send it in the call: you would change it in the draft and create a new version.

Delete what you created

  1. In Prompt management, select descripcion-producto and choose Delete.
  2. Enter confirm and choose Delete. All the versions are deleted, although AWS keeps deleted prompts on its for up to 14 days.

If your account is a new experience account

Bedrock is on the free plan, and the new experience policy allows Bedrock actions in your project's Region, so the only thing that changes in this lab is the model. In Configurations, don't choose a model that in us-east-2 only appears with an inference profile, which are the ones whose ID starts with us. or global.. An inference profile can handle your call in another Region, and the new experience only lets you use your project's Region. For example, Amazon Nova Lite and Mistral Large 3 work, because they are invoked within us-east-2.

Next

  • Create a prompt using Prompt management: https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-management-create.html
  • cloud path practice exams: /examenes?lang=en