esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
  • Download ResumeContact
Let’s talk

I’ll build the agent for it.

Why Template and Version Your Prompts?

Why keep prompts as templates in code with version ids, what goes wrong without them, and how to explain rollback and caching for your AI interview.

In short

A template keeps the fixed wording of a prompt in one place, with blanks for the changing parts. Versioning records each change, so you can test it, review it, and roll back when an update breaks a reply.

11 min readBeginnerCommon · estimateFacts checked 26 November 2026

Say it out loud

Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.

A prompt template keeps the fixed wording of a prompt in one file, with blanks for the things that change, like the customer's data. Versioning saves each edit as a version with its own id, so I can test a change, review it, and roll back to the last good version when a reply goes wrong. Keeping the fixed text identical also helps caching, which keeps cost down. Without both, copies drift apart and nobody knows which wording gave the bad answer.

What is a prompt template and a prompt version, in plain words?

A prompt is the text you send to a model: the rules, the context and the question. In a real app the rules barely change, but the question and the data do. A template keeps the rules in one place and leaves a blank for each thing that changes.

A bank uses a standard letter for declined card payments. The legal wording stays fixed, and the customer's name, the amount and the date go into the blanks. Nobody retypes the letter for each customer, and the bank can change the wording once, with a record of what it said before.

An AI version works the same way. A support assistant has fixed rules, and its blanks hold the customer's account, the current policy and the customer's message. A version is a saved copy of that template with its own id, so every reply can be traced back to the exact wording that produced it.

Key words

Template
Fixed prompt text with named blanks.
Variable
A blank that gets a real value on each call.
Prompt version
One saved state of the template, with its own id.
Regression test
A fixed set of past cases, run again after each change.
Rollback
Switching back to an older version that worked.

Why not just type the prompt into each place?

Typed copies look harmless at first. A claims triage agent might have one prompt in the intake service, another in the refunds service and a third in the call-back bot. All three start the same. A month later, one copy has a fix for ambiguous policy numbers, and the other two still send the old wording.

Copied prompts drift, one shared template does not

Copy and paste

Three services

each keeps its own copy of the rules

One template

One prompt file

every service imports the same file

Copies drift apart

a fix reaches only one copy

Same wording everywhere

one edit changes every caller

  1. 1Each service pastes its own copy, so the same fix has to be made three times.
  2. 2Every service imports one file, so one edit reaches all three.
Copied prompts drift apart, so a fix lands in one service and the others keep the old wording. One shared template reaches every caller with a single edit.

A template also makes the changing values explicit. The values become typed function arguments in your code, so you can check them before the model sees them: a claim number must be a string, and a policy code must be on the known list. A missing blank raises an error, as the sketch below shows. OpenAI's own migration guide makes the same move, replacing prompt variables with typed function arguments.

Tip

Asked why not just copy the prompt? Say copies drift apart, and that one template with typed inputs keeps every caller on the same wording.

How does versioning make a bad release easy to undo?

A version is a saved state of the template with its own id. Keep it in the code repository, so each edit is a commit (a saved, named change in the code's history) with an author, a date and a reason, and each release goes through a pull request (a proposed change that a colleague reviews before it is merged). OpenAI's migration guide says to move versioning to your repo, using commits, review, and tests or evals.

  • “Move prompt content into source code so prompt changes go through the same review and release process as product logic.”

    OpenAI

  • “Prompt templates can be versioned and used with generative models on Agent Platform.”

    Google Cloud

Finding and undoing a bad prompt release

Wrong fee quoted

a bank bot quotes an old card fee

Find the version

the log shows which wording ran

Re-run saved cases

the cases catch the wrong fee

Roll back to last good id

the last version that passed

  1. 1A customer complaint starts the search.
  2. 2The version id in the reply's log shows exactly which wording produced the answer.
  3. 3The saved cases confirm the fault, and the team switches back to the last version that passed.
When a reply goes wrong, the version id in the log shows which wording ran. The team re-runs the saved cases, then rolls back to the last version that passed.
  1. 1

    Every change is a commit

    Each edit is saved with who made it, when, and why.

  2. 2

    Each release gets an id

    The id goes into the log of every reply, so a bad answer can be traced.

  3. 3

    Tests run before release

    A fixed set of past cases must still pass, and a new failure becomes a new case.

  4. 4

    Rollback is a switch back

    Point the app at the last version that passed. Nothing is retyped.

Here is the idea in a short Python sketch. A missing blank stops the call, and the version id is a hash of the wording, so the same text always gets the same id.

Python
# A versioned prompt for a claims triage agent. Standard library only.
import hashlib
from string import Template

TRIAGE_V3 = Template(
    "You triage insurance claims. Answer fast-track, review or decline.\n"
    "Policy: $policy\n"
    "Claim: $claim"
)

def version_id(template):
    # The same wording always gives the same id, so a log shows exactly which text ran.
    return "triage-" + hashlib.sha256(template.template.encode()).hexdigest()[:8]

def render(template, **values):
    # substitute() raises KeyError on a missing blank, so half a prompt never goes out.
    return template.substitute(**values)

print("version:", version_id(TRIAGE_V3))
print(render(TRIAGE_V3, policy="motor-comprehensive", claim="Rear bumper, parked car, 1,240 USD"))
try:
    render(TRIAGE_V3, policy="motor-comprehensive")
except KeyError as err:
    print("blocked, missing blank:", err)

Output

version: triage-92cb6a1f
You triage insurance claims. Answer fast-track, review or decline.
Policy: motor-comprehensive
Claim: Rear bumper, parked car, 1,240 USD
blocked, missing blank: 'claim'

How do caching and model changes affect a template?

Caching is a cost saver. Tokens are the small pieces of text a model reads, roughly part of a word each. When a prompt starts with the same tokens as an earlier request, the model can reuse work it already did for that start. OpenAI's caching guide says reused input tokens get a reduced rate, and that the reuse covers the unchanged tokens at the beginning of a prompt.

  • “Keep static content first and dynamic content later to preserve prompt caching benefits, since cache hits depend on exact prefix matches.”

    OpenAI

So the order inside a template matters. Fixed rules and examples go first, and the customer's data goes last. A template that puts a timestamp or a random example at the top can break the cache on every call, and every call pays the full price for the prompt again.

A prompt version alone does not pin behaviour. OpenAI advises pinning production apps to specific model snapshots (fixed, dated builds of a model) to ensure consistent behaviour, and notes that even different snapshots within one model family could produce different results. So the release record should name the prompt version and the model snapshot together. Rolling back the prompt does not undo a model change.

Tip

Asked how you would handle a model upgrade? Say you run the saved test cases on the new model before switching, and keep the old prompt and model pair ready to restore.

How would you change a prompt in a live claims app?

A claims team wants a new rule for ambiguous policy numbers. The change is small, but a wrong triage sends a valid claim to decline.

  • Without versions

    Edit and hope

    Someone edits the live prompt, and the complaints show up a week later with no record of what changed.

  • With versions

    Test, then release

    The change is a commit, the saved cases must still pass, and the release gets an id. If complaints rise, the team rolls back to the last good id.

What does the interviewer want to hear?

A strong answer covers

  • A template: fixed rules in one place, typed blanks for the changing data.
  • A version: a saved state with its own id, shown in every reply's log.
  • Why it matters: copies drift apart, and nobody knows which wording failed.
  • Safe change: commits, a review, and regression tests before release.
  • Rollback: switch back to the last version that passed.
  • The honest point: a prompt version does not pin the model, so record both.

Common traps

  • Trap"Every team can keep its own copy of the prompt."

    BetterCopies drift apart. Keep one template that every caller imports.

  • Trap"A backup of the file is the same as versioning."

    BetterA backup has no reason, no test and no id in the log. Use commits, reviews and version ids.

  • Trap"Just edit the live prompt and watch the complaints."

    BetterRun the saved cases on the change first, then release it under an id you can roll back.

Can you spot the safe way to call a prompt?

Spot the safe call

Which option is a safe way to send a claims triage prompt?

Quick check

A bank's support bot starts quoting an old card fee after a prompt edit. What do you check first?

Can you answer these from memory?

Flash cards · tap a card to flip it

1 / 6

What will they ask next?

  1. Q088What is prompt caching, and how does it save money?13 min
  2. Q089How do you order a prompt so caching hits?12 min
  3. Q100How do you test prompts systematically?12 min
  4. Q102Why do prompts break when you switch models?11 min
  5. Q257How do you regression-test prompts?12 min

Last updated on 26 November 2026

Shipping an AI feature that changes every week?

I design and build AI products and agents, including the prompts, tests and release process behind them. Book a short call and tell me what you need to change safely.