Skip to course content
Free generative AI app course

Generative AI Application Development with Python

Unit 04.03: Versioning a prompt like code

A prompt is behaviour, so it is code: versioned, retained, and recorded with every response.

Old versions stay readable

Three prompt versions with retirement dates.

The code shows which is active.

import json

PROMPTS = {
    "reply-v1": {"text": "Answer the question.", "retired": "2026-05-02"},
    "reply-v2": {"text": "Answer using only the POLICY.", "retired": "2026-06-14"},
    "reply-v3": {"text": "Answer using only the POLICY. Quote the line you "
                         "relied on. If it does not cover the question, say so.",
                 "retired": None},
}
print(json.dumps({k: {"retired": v["retired"]} for k, v in PROMPTS.items()},
                 indent=1))

active = [k for k, v in PROMPTS.items() if v["retired"] is None]
print(f"\nactive: {active}")
print(f"a trace recording only the model cannot explain a v2 run today")

# A prompt is behaviour, so it is code: version it, keep old versions readable,
# and record which one produced every response. It changes weekly and is almost
# never thought of as a deploy.

A trace that records the model but not the prompt version cannot explain a run made before the last edit - and prompts are edited weekly by people who do not think of it as a deploy.

Keeping retired versions readable is what lets you reproduce an old behaviour rather than infer it.

The mistake this prevents

The mistake is editing prompts in a dashboard or a database row. They then change without review, without a deploy record, and without a way to roll back - while being the single largest determinant of the app's behaviour.

Takeaway

Version prompts like code, keep retired versions readable, and record the version with every response. A prompt edit is a behaviour change.