Sub topic 7
Recording metadata and change notes
A version number tells you that two prompts differ. It doesn't tell you how they differ, why someone changed them, or what the application must supply. Metadata and change notes cover those gaps. This chapter assumes you can read YAML and Python, use Git, and have already stored templates as files, as covered in the earlier chapters on rendering and storage.
Why a version number is not enough
Suppose a prompt file is called 1.3.0.yaml. A teammate asks a few questions:
- What changed since
1.2.0? - Is it safe to deploy without changing application code?
- Who approved it?
- Which variables does it need?
Git history can answer some of these. Commit messages are free-form, though, and they describe a commit rather than the prompt version. A reviewer reading a pull request shouldn't have to reconstruct intent from a diff of English sentences. Putting the key facts inside the prompt file means they travel with the version wherever it is loaded, copied, or logged.
What belongs in the metadata
Keep the metadata small. Each field should answer a question someone will really ask. The example from the storage chapter already has the core four fields plus the template:
name: summarize
version: 1.2.0
changelog: Ask for a one-sentence answer when the text is short.
variables: [style, text]
template: |
Summarize the following text in $style style.
If the text is under 50 words, answer in one sentence.
$text| Field | Question it answers | Who reads it |
|---|---|---|
| `name` | Which prompt is this? | Loader, logs |
| `version` | Which revision of it? | Loader, logs, rollback |
| `changelog` | What changed and why? | Reviewers, on-call engineers |
| `variables` | What must the caller supply? | Application code, validation |
| `template` | What text is sent to the model? | The model |
Teams often add optional fields as needs appear:
owner: a person or team to ask about the prompt.created: the date, which helps when you audit old versions.model_hint: the model the prompt was tested against.status:draft,released, ordeprecated.
Add a field only when something reads it. A field that nobody checks becomes stale, and stale metadata is worse than none because people trust it.
Metadata versus model settings
Settings such as temperature and the model name can live in the prompt file or in application configuration. Either choice works if you stay consistent.
- In the prompt file: the prompt and its tuned settings change together, and rollback restores both.
- In application config: you can change settings without a prompt release, but a rollback of the prompt alone may not restore the earlier behavior.
Whichever you choose, record the settings with each call so outputs can be traced later. The observability chapter covers that.
Choosing a versioning rule
The previous chapter introduced version schemes. Semantic versioning (MAJOR.MINOR.PATCH) works well for prompts if you define each level in terms of what callers and outputs experience. Here is one workable definition:
| Bump | Use when | Example |
|---|---|---|
| Major | The variable set or the expected output format changes, so callers or parsers must change | Adding a required `language` variable; switching output from prose to JSON |
| Minor | Behavior changes on purpose but callers and parsers are unaffected | Adding an instruction to answer in one sentence for short texts |
| Patch | Wording changes with no intended change in behavior | Fixing a typo; rephrasing for clarity |
Two caveats apply:
- The patch level is a claim about intent, not a guarantee. With a language model, rewording a sentence can shift outputs. Treat a patch bump as "we don't expect behavior to change" and still run the regression suite.
- Write the rule down. Put it in the repository's README, so two people don't bump the same kind of change differently.
Writing change notes that help
A change note has to be useful when read months later by someone who wasn't in the room. A good note names what changed, and where it helps, the reason.
Compare these two notes:
- Weak:
Updated prompt. - Weak:
Improved summaries. - Better:
Ask for a one-sentence answer when the text is short. - Better:
Fix: stop quoting the input verbatim; the model was echoing long passages.
The better notes share three traits:
- They begin with a verb that states the action.
- They say what changed in the prompt's behavior, not only in its wording.
- They give the reason when it isn't obvious.
If a change needs more than a line or two, keep changelog as a short summary and put details in the pull request description. You can use a multi-line YAML block for the field too, but a long changelog is a sign that the change should have been split into several versions.
Notes for breaking changes
A major bump should say what callers must do. For example:
name: summarize
version: 2.0.0
changelog: |
BREAKING: requires new variable `language`.
Output is now a single paragraph with no heading.
Migrate callers by passing language="English" to keep old behavior.
variables: [style, text, language]
template: |
Summarize the following text in $style style, written in $language.
If the text is under 50 words, answer in one sentence.
Reply with one paragraph and no heading.
$textStarting the note with BREAKING: makes it easy to scan for and to search in a log of changes.
Keeping metadata honest
Metadata drifts from reality when it is maintained by hand and checked by no one. The most common drift is the variables list. Someone adds $audience to the template and forgets to declare it, or removes a placeholder and leaves it listed. Rendering then fails in production, or the application passes a value that is silently unused.
You can catch this with a short validator that runs in CI whenever a prompt file changes. It checks that:
- all required fields are present;
versionhas theMAJOR.MINOR.PATCHform;- the version and name agree with the file's location (
prompts/<name>/<version>.yaml); - the changelog isn't empty;
- the declared variables exactly match the placeholders in the template.
import re
import sys
from pathlib import Path
import yaml
REQUIRED_FIELDS = {"name", "version", "changelog", "variables", "template"}
SEMVER = re.compile(r"^\d+\.\d+\.\d+$")
PLACEHOLDER = re.compile(r"\$(?:(\$)|(\w+)|\{(\w+)\})")
def used_variables(template_text):
"""Return the placeholder names in a string.Template-style text."""
names = set()
for match in PLACEHOLDER.finditer(template_text):
if match.group(1): # "$$" is an escaped literal dollar sign
continue
names.add(match.group(2) or match.group(3))
return names
def check_prompt_file(path):
"""Return a list of problems found in one prompt file."""
path = Path(path)
data = yaml.safe_load(path.read_text())
if not isinstance(data, dict):
return [f"{path}: file does not contain a mapping"]
problems = []
missing = REQUIRED_FIELDS - data.keys()
if missing:
return [f"{path}: missing fields {sorted(missing)}"]
if not SEMVER.match(str(data["version"])):
problems.append(f"{path}: version {data['version']!r} is not MAJOR.MINOR.PATCH")
if str(data["version"]) != path.stem:
problems.append(f"{path}: version {data['version']} does not match file name")
if data["name"] != path.parent.name:
problems.append(f"{path}: name {data['name']!r} does not match directory")
if not str(data["changelog"]).strip():
problems.append(f"{path}: changelog is empty")
declared = set(data["variables"])
used = used_variables(data["template"])
if declared != used:
problems.append(
f"{path}: declared-only={sorted(declared - used)} "
f"template-only={sorted(used - declared)}"
)
return problems
if __name__ == "__main__":
all_problems = []
for file in sorted(Path("prompts").glob("*/*.yaml")):
all_problems.extend(check_prompt_file(file))
for problem in all_problems:
print(problem)
sys.exit(1 if all_problems else 0)Run it from the repository root with python check_prompts.py. It exits with status 1 when any file has a problem, so a CI job can fail the build on it.
The version value deserves care. YAML reads 1.2.0 as a string because it has two dots, but it would read 1.2 as a number. The validator calls str() on it and checks the pattern, so a shortened version such as 1.2 is rejected.
Immutability: the rule that makes metadata trustworthy
Once a version is released, never edit its file. If 1.2.0 is edited in place, the logs that say "prompt 1.2.0 produced this output" now point at text that is different from what ran. The change note becomes false too.
To fix a mistake in a released version, create 1.2.1. You can enforce the rule in CI by failing any pull request that modifies an existing released file. A simple check compares the changed files against the main branch and rejects changes to files that already exist there. Drafts, marked with status: draft, can be exempt.
How the pieces fit together
A change moves from an edit to a recorded, reviewable version. Each step produces something that another step uses.
Common mistakes
- Copying the changelog forward. If
1.3.0still carries the note from1.2.0, the history is wrong. The validator can't catch this directly, but a reviewer can. A CI step that compares the changelog with the previous version's and warns on a match also helps. - Bumping the wrong level. Adding a variable and calling it a minor change breaks every caller that doesn't pass it. The
variablescheck catches this at render time, and the major rule prevents it earlier. - Recording what changed but not why. A diff already shows what changed. The note's value is the reason.
- Storing the version only in the filename. Then logs and loaded objects lose it. Keep the
versionfield inside the file so it travels with the loaded data.
Summary of the working model
Metadata turns a prompt file into a self-describing artifact. The version identifies it, the changelog explains it, and the variables list states its contract with callers. A validator keeps those claims aligned with the template, and the immutability rule keeps them true over time. The next chapter uses these fields to pin an application to one version and to roll back.
Exercise
A teammate adds the placeholder $audience to the template in prompts/summarize/1.2.0.yaml, which is already deployed, and leaves the variables list as [style, text]. Name two problems and say what the correct fix is.
Show answer
First, the declared variables no longer match the template's placeholders, so the validator reports template-only=['audience'] and rendering would fail or omit a needed value. Second, the file was edited in place after release, so logs that cite 1.2.0 now point at different text. The fix is to revert 1.2.0 to its released content and create a new version. Because it adds a required variable, callers must change, so it should be 2.0.0 with variables [style, text, audience] and a changelog that starts with BREAKING and explains how to migrate.
Exercise
Choose the version bump for each change and justify it: (a) fix a spelling mistake in the instructions; (b) add the sentence "Answer in one sentence if the text is under 50 words"; (c) change the output format from prose to JSON that a parser reads.
Show answer
(a) Patch, because the wording changes with no intended change in behavior, although the regression suite should still run. (b) Minor, because behavior changes on purpose but callers and parsers are unaffected. (c) Major, because downstream code that reads the output must change to handle the new format.