AWS Builder Center

Bedrock Prompt Management: Version Prompts in Python

Stop hardcoding prompts. Amazon Bedrock Prompt Management lets you version, test, and ship prompts in Python via the Converse API—here's a working walkthrough.

Series: Bedrock Builder's Log (6 articles)

  1. …
  2. 5
    Bedrock Prompt Management: Version Prompts in Python This article
Lead Data Scientist

Treat Prompts Like Code: Amazon Bedrock Prompt Management in Python

Here's a smell I still see in production GenAI codebases: the single most important part of the application — the prompt — lives as a triple-quoted string buried in  handler.py . Someone tweaks a word, ships it, and there's no version, no diff, no rollback. When quality drops next Tuesday, nobody can say what changed.
Amazon Bedrock Prompt Management fixes that. It gives your prompts a home outside your code: named prompts, immutable versions, variables, and a clean way to invoke a specific version through the Converse API. Think of it as Git tags for your prompts. Below is a complete, copy-pasteable walkthrough — create, version, invoke, and tear down. The full script and an IAM policy snippet are on GitHub:  AashimaYuthika/bedrock-prompt-management-python .

Prerequisites

  • An AWS account with Bedrock access in a supported Region (this uses  us-east-1 ).
  • Model access enabled for the model you reference (here,  amazon.titan-text-express-v1 ).
  •  boto3  installed ( pip install boto3 ) and credentials configured.
  • IAM permissions for  bedrock:CreatePrompt ,  CreatePromptVersion ,  GetPrompt ,  ListPrompts ,  DeletePrompt , and  bedrock:InvokeModel  on the prompt ARN.
One key distinction to keep straight: build-time operations (create/version/delete a prompt) use the  bedrock-agent  client, while runtime invocation uses  bedrock-runtime . Mixing those up is the most common first-run error.

Step 1 — Create a prompt with variables

Variables use  {{double_brace}}  syntax, so the same prompt serves many inputs.
python
import boto3

# Build-time client
agent = boto3.client(service_name="bedrock-agent", region_name="us-east-1")

response = agent.create_prompt(
name="MakePlaylist",
description="Generates a themed playlist.",
variants=[{
"name": "Variant1",
"modelId": "amazon.titan-text-express-v1",
"templateType": "TEXT",
"inferenceConfiguration": {"text": {"temperature": 0.8}},
"templateConfiguration": {
"text": {
"text": "Make me a {{genre}} playlist consisting of "
"the following number of songs: {{number}}."
}
},
}],
)

prompt_id = response["id"]
print("Draft prompt:", prompt_id)
At this point you have a draft — editable, not yet deployable. That's deliberate: drafts are your working copy.

Step 2 — Cut an immutable version

A version is a frozen snapshot. This is the artifact you point production at, so it can never drift out from under you.
python
version_resp = agent.create_prompt_version(promptIdentifier=prompt_id)

prompt_version = version_resp["version"] # e.g. "1"
prompt_version_arn = version_resp["arn"] # arn:aws:bedrock:...:prompt/<id>:1
print("Pinned version:", prompt_version, prompt_version_arn)
Every edit-and-version cycle gives you a new number. Rolling back is just pointing at the previous ARN — no redeploy of application code required.

Step 3 — Invoke the versioned prompt

Now switch to the runtime client. The trick that surprises people: you pass the prompt ARN as the  modelId , and you don't send  messages  or  system  at all — the template already carries them. You only supply the variables.
python
runtime = boto3.client(service_name="bedrock-runtime", region_name="us-east-1")

result = runtime.converse(
modelId=prompt_version_arn, # the versioned ARN, not a model name
promptVariables={
"genre": {"text": "lo-fi jazz"},
"number": {"text": "5"},
},
)

print(result["output"]["message"]["content"][0]["text"])
Because the model, temperature, and template all live in the version, your calling code shrinks to "which prompt, what inputs." Swap the ARN's version suffix and you've A/B-tested a new prompt with zero code changes.

Step 4 — Clean up

Prompt Management has no standing charge, but leaving stray prompts around clutters the account and your IAM blast radius. Delete the version, then the prompt.
python
agent.delete_prompt(promptIdentifier=prompt_id, promptVersion=prompt_version)
agent.delete_prompt(promptIdentifier=prompt_id)

Cost implications

Prompt Management itself is free — there's no charge to store or version prompts. You pay only the normal per-token inference cost when you call  converse . So the versioning discipline is, genuinely, upside with no line item attached. The only cost lever here is the model and temperature baked into each variant.

Why this matters — what I'd actually do

The feature is simple; the practice is where the value is. Three things I'd put in place on any real project:
  • Never let application code invoke a draft. Point prod at a pinned version ARN, injected as an environment variable. Drafts are for the console and experiments.
  • Treat the version ARN like a deploy artifact. Store "prod is on  :7 " in your config, and make promotion an explicit, reviewable change — the same way you'd bump a container tag.
  • Keep the template out of the diff noise. When product asks "why did tone change last release?", you want to answer with a prompt version number, not a  git blame  on a 200-line handler.
The mental shift is small but real: prompts stop being string literals and start being versioned dependencies. That's the difference between "we think we changed the prompt" and "we shipped prompt v6, rolled back to v5, incident closed."
What's the messiest place a prompt currently lives in your codebase — and would a pinned version ARN have saved you a bad afternoon? I'd love to hear how you're versioning prompts today.
.
.
.
#AWS #AmazonBedrock #GenAI #MachineLearning #LLMOps #Python

Series: Bedrock Builder's Log (6 articles)

  1. …
  2. 5
    Bedrock Prompt Management: Version Prompts in Python This article
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article