Lesson 4 of 5 CI/CD and Testing for ML and AI

Managing Prompts Centrally with Amazon Bedrock

This lesson explains how managing prompts centrally, with versions, variables and settings, makes generative AI applications reproducible, reviewable and easy to roll back.

Learning outcomes

After completing this lesson, you will be able to:

  • Store prompts with templates and variables in Prompt Management.
  • Use prompt optimisation and Bedrock Flows.
  • Release prompt changes like code changes.

Prompt Management

Amazon Bedrock Prompt Management stores prompts as resources. A prompt has a template with variables in double curly braces, a chosen model, inference parameters and optionally a system prompt and tool configuration, and can have several variants to compare side by side. The prompt is edited as a draft; creating a version freezes an immutable snapshot. Applications pass the prompt version ARN as the model ID to Converse or InvokeModel and supply variable values, so the prompt text never lives in application code.

resp = bedrock_runtime.converse(
    modelId="arn:aws:bedrock:us-east-1:111122223333:prompt/PROMPT123:4",   # prompt version 4
    promptVariables={"customer_name": {"text": "Ana"}, "issue": {"text": "late delivery"}},
)
True or false

Prompt Management

Exam skills 3.3.7

Check how Amazon Bedrock Prompt Management stores prompts.

Log in to try this activity Interactive activities are free with an account.

Optimization and flows

Amazon Bedrock prompt optimisation rewrites a prompt to suit a chosen model, giving a good starting point that is then tested on an evaluation set. Amazon Bedrock Flows links prompts, knowledge bases, Lambda functions, conditions and agents into a workflow, which also has versions and aliases, so whole prompt chains are released as a unit.

Prompts can also be stored as files in Git, which gives familiar review processes, but then versioning, rollout and rollback must be built around the repository rather than provided by Prompt Management.

Release practice

Treat a prompt change like a code change: propose it, test it against an evaluation set, create a version, and update the application's configuration (for example, a Parameter Store value holding the version ARN) through the deployment pipeline. Rolling back means pointing to the previous version. The following table summarises the features.

FeaturePurpose
Template variablesReuse one prompt with different inputs
VariantsCompare prompt wordings or models side by side
VersionsImmutable snapshots for release and rollback
Prompt optimisationRewrite a prompt for a target model
Bedrock FlowsChain prompts, knowledge bases and code with versions and aliases

The following diagram compares five copies of a summarisation prompt embedded in different services with a single managed prompt.

Consolidating the summarisation prompt. Before, five microservices embedded slightly different copies, and no one knew which produced a complaint. After, one managed prompt with variables has immutable versions; services call Converse with the version ARN from Parameter Store and log it with each invocation, so a change is a parameter update and every response is traceable.
The scenario is illustrative.
Put in order

Release a prompt change

Exam skills 3.3.7 · 3.3.9

Arrange the steps for releasing a change to a managed prompt.

Log in to try this activity Interactive activities are free with an account.
Worked example

Prompts scattered in code

Five microservices each embed slightly different copies of the same summarisation prompt, and nobody knows which version produced a complaint last Tuesday.

  • Create one managed prompt with variables for document type and length, and test it in Prompt Management.
  • Create version 1 and store its ARN in Parameter Store; all services call Converse with that ARN.
  • Log the prompt version ARN with each invocation.

Future changes become version 2, 3 and so on, deployed by updating one parameter. Logs now show exactly which version produced any response.

Check yourself

How can an application use a managed prompt directly?

Show answer

By passing the prompt version's ARN as the model ID.

Exam Tips

Remember for the exam

  • Central, versioned prompts with variables: Bedrock Prompt Management.
  • Prompt versions are immutable; roll back by referencing the previous version.
  • Applications can pass a prompt version ARN as the model ID.
  • Chain prompts, knowledge bases and Lambda: Bedrock Flows.
  • Log the prompt version with every invocation.