# 25.1 A prompt is code: versioned, reviewed and tested (/building-ai-workers/prompts-and-structured-output/a-prompt-is-code)

---
type: Document
title: "25.1 A prompt is code: versioned, reviewed and tested"
description: "Why a prompt changes the way code changes: one versioned file, reviewed in a pull request, with the suite run on every change."
status: stable
order: 325.01
ksor:
  owner: team:panaversity
  audience:
    - public
  approval:
    by: process:panaversity
    at: 2026-11-30T00:02:23Z
chapter: '25'
part: III
expert_status: co-build
concepts: [ "25.1" ]
last_verified: '2026-11-29'
sources:
  - id: anthropic-cookbook-prompt-versioning
    title: 'Managed Agents tutorial: prompt versioning and rollback, Claude Cookbook (verified 2026-11-29)'
    resource: https://platform.claude.com/cookbook/managed-agents-cma-prompt-versioning-and-rollback
  - id: openai-text-generation
    title: Text generation, OpenAI API docs (verified 2026-11-29)
    resource: https://developers.openai.com/api/docs/guides/text
  - id: openai-migrate-prompt-objects
    title: Migrate from prompt objects, OpenAI API docs (verified 2026-11-29)
    resource: https://developers.openai.com/api/docs/guides/prompting/migrate-from-prompt-object
  - id: langfuse-prompt-management
    title: Prompt Management, Langfuse docs (verified 2026-11-29)
    resource: https://langfuse.com/docs/prompt-management/overview
generated:
  at: 2026-11-30T00:02:23Z
  by: esl-rewrite/1.2.0+ksor.1
trust_tier: unverified
build_id: sha256:cc6fd9ac5f72207d4365ecbda63d87d1b64f99e05519b358a45b9f5d9bfd6f8f
dirty: true
ksor_version: 0.0.60
---

**In everyday life.** A bakery bakes its bread from a recipe card on the wall. One morning the baker thinks the bread needs less salt, and changes the card with a pen. Nobody tastes the new bread before the shop opens. By noon, forty customers have bought a loaf that no one tried. A careful bakery writes a new card with a date on it, bakes one tray, and has someone taste it. Only then does the new card go on the wall. The old card goes in a drawer, in case the new bread is worse. In this concept, the card is the prompt, the tasting is the suite, and the drawer is the old version.

**What you will learn.** You practice this in Lab 25, Tasks 1 and 2, where one changed line reaches production only through a pull request.

- Why does a prompt change the way code changes?
- What do versioned, reviewed and tested mean for one file?
- Where else can a prompt live, and what does each home cost?

**Why it matters.** A changed prompt changes every answer, and nobody reads every answer.

**At work.** Monday, April 19, 2027. INV-8340 is in the morning report, and the builder already knows which file to change: the extraction prompt. The fast way is to open the file on the server, add a line and save. That is also how the builder tested on Friday: one invoice, one answer, one person reading. But tomorrow at 7:10 the new words will read every new invoice, with nobody reading the answers. So who reads the results of a changed prompt? Not the builder. The suite does, and a suite can only test something that does not change.

### Why does a prompt change the way code changes?

**Because the reader of its results is now a suite, and not a person.** When a person read each answer, the same person read again after each change. [Chapter 5](../../managing-ai-workers/the-four-part-brief/overview.md) taught that habit: "Read the result as a test, and change only the part that failed". Nobody reads a thousand invoices again. Chapter 24's suite does it for you: it runs every case at each change and compares each answer with Ana's label.

That gives a prompt the same three needs as code. The suite must know which words it tested, so the prompt needs a version. A person must see what changed, so the change needs a review. And the change must not reach the 7:10 run until the cases pass, so it needs a test.

Chapter 24 showed this work, ten days earlier in the story. On Friday, April 9, a pull request shortened the worker's prompt. The suite ran, one answer was marked incorrect, and the change did not merge until the cut line was put back. No customer and no morning report ever saw the broken prompt.

### What do versioned, reviewed and tested mean for one file?

**Each word is one thing you do to the file.** In [21.13](../agent-loop-by-hand/versions-models-and-keys.md) the prompt was pinned as "A file with a version in its name, `prompts/ap-worker.v1.md`, reviewed like code". This concept adds the third word, tested.

| The word | What you do | What it gives you |
| --- | --- | --- |
| *Versioned* | Copy the file to a new name, `prompts/ap-worker.v2.md`, and change the copy. One line in the code names the version it loads | Every answer can be traced to the exact words that produced it. Going back is a change to one line |
| *Reviewed* | Open a pull request. The reviewer compares v1 with v2 and sees only what changed. Where the changed words state an AP rule, Ana reads them | A second reader for the words, before any invoice meets them |
| *Tested* | The suite runs on the pull request. Checks by code run on every pull request, and the judge runs when the worker's prompt, the model or the golden set changes | Every case read again, with no person reading |

<!-- OPEN: the file name of the extraction prompt that Lab 24 adds is not in the spec or in specs/labs. This section names the worker's prompt file, which the book already has, and says the extraction prompt is kept the same way. Name the real file once the lab fixes it. -->

The extraction prompt is kept the same way, as its own file in `prompts/`. Keep each prompt in one file, and let code fill in the parts that differ from run to run, such as the invoice. And never edit a version that has shipped, which means it has reached production. A file that changes under its name is no longer a version.

### Where else can a prompt live, and what does each home cost?

**In the repository, the price is speed.** A one-word change needs a new file, a pull request and a suite run, and a live suite run costs money. That price is fair for any prompt whose answers nobody reads.

**On a server, the price is the review.** Some teams keep prompts in a registry, a service that stores each prompt by version. A prompt update can then go live without a deployment of the code.[^langfuse-prompt-management] A hosted agent works this way too. Claude's Managed Agents is Anthropic's service that runs a worker for you (Chapter 23). There, each update to an agent makes a new version that cannot be changed. One run, called a session, chooses its version by id.[^anthropic-cookbook-prompt-versioning] Anthropic's own worked example names the cost: "There's no built-in approval workflow on agents.update. Any key in the workspace can call it." Its answer is that production callers always pin an explicit version, and that pinned number is the thing under change control.[^anthropic-cookbook-prompt-versioning] That is why [23.4](../hosted-agents/resources-as-code.md) kept the worker's definition as a file and applied it with a plan.

**OpenAI has moved the same way.** Its reusable prompt objects, the `v1/prompts` API, are scheduled to shut down on November 30, 2026. Its guide says: "Store production prompts in your application code instead of creating reusable prompt objects."[^openai-migrate-prompt-objects][^openai-text-generation]

<!-- OPEN: this page was drafted on 29 November 2026, one day before the shutdown date. On the day the page is approved, check the deprecations page and write "shut down on November 30, 2026". Change the stem of quiz item 25.1-06, "are scheduled to shut down", on the same day. -->

Whichever home you choose, two things stay yours: a version that never changes under its name, and a test that runs before the version is used.

**The operating rule:** a prompt reaches production only as a named version that the suite has read.

**Do this now.** Ask your coding agent to find every prompt your project sends. Copy this line:

> List every prompt this project sends to a model. For each one, name the file that holds it, the place where its version is set, and the test that would fail if I changed one word of it. Change no file.

A prompt with no file, no version or no test is one that only a person is reading.

[^langfuse-prompt-management]: Prompt Management, Langfuse.
[^anthropic-cookbook-prompt-versioning]: Managed Agents tutorial: prompt versioning and rollback, Claude Cookbook.
[^openai-migrate-prompt-objects]: Migrate from prompt objects, OpenAI.
[^openai-text-generation]: Text generation, OpenAI.
