Prompts and context as code
What an AI engineer is accountable for around the text a model reads: who may change each part, what a change carries with it before it ships, and how you read a regression run when one word moves cases you never meant to touch
Esohe runs the 90-case eval set on RULES v12 and on v13, where v13 changes one word in rule 9. v12 passes 82 cases and v13 passes 83. The four double-resend cases she aimed at now pass. What does she know?
A prompt looks like writing, so people edit it as they edit writing: open the file, change a sentence, read it back, move on. It behaves like code. A change of one word can alter what a system does on cases you never thought of, and it fails quietly: the model still answers, fluently, and the answer is wrong in a new place. This chapter is about the job around the text: what counts as part of the prompt, who may change each part, what a change must carry before it reaches a customer, and how you read the result.
The technique belongs to the course. Immutable bundles, content hashes, registries, bucketed rollout and the statistics of a paired comparison are taught in prompt management, and wiring the gate into CI is in evals in CI. Read those for how. This chapter is about what you answer for. It assumes the gate from an AI engineer’s week and the habits in the track’s philosophies. The running example is Wrenpost’s support assistant: RULES v12, a 6,000-token handbook (HANDBOOK 2026-10) and three tools, lookup_message, resend_message and sender_id_status.
The figures match the earlier Wrenpost chapters but count different things, so here is how they fit.
- Traffic. The assistant handles about 700 conversations a week. Four weeks is about 2,800, which is what this chapter uses because the double-resend count is over four weeks. The other chapters round the same traffic to about 3,000 for a calendar month.
- The eval set. The 90 cases here are the assistant’s whole regression set: the 30 cases from the week chapter, the 50 cases of
RESEND-EVAL v1from the eval-set chapter, and ten added since, among them the double-resend and Kenyan cases below. The 50 are a gate for the resend feature alone. The 90 are what you run before any rules change, and each case runs three times. - The rules. RULES v12 is the live rules of both earlier chapters, with the resend rules that passed the eval-set gate; rule 9 is one of them. RULES v13 appears only here, as a candidate against v12.
The model: the prompt is a bundle of parts with different owners
Ask a team what “the prompt” is and you get one file. The model reads more than that. At Wrenpost it reads the tool descriptions, the numbered rules, the handbook, the records the tools return, and the conversation. Each part is written by someone different, changes at a different rate and fails differently. If you treat them as one string, you cannot say who was allowed to change what.
| Part | At Wrenpost | Who proposes changes | Versioned as | What checks a change |
|---|---|---|---|---|
| Rules | RULES v12, the numbered instructions | Esohe, the product manager for support tooling, support operations | RULES vN, immutable once released |
Paired run; Esohe reviews the diff |
| Handbook | HANDBOOK 2026-10, 6,000 tokens of policy and how-to | The support operations lead | Dated name | The same paired run |
| Tool descriptions | The text the model reads about each tool | Esohe with the tool’s owner | A tool-set version | Paired run, and the tool’s own tests |
| Tool behaviour | The code behind resend_message |
The owning team (the send path belongs to Routing) | Normal releases | Unit tests, then a run |
| Tool results | The delivery record, and the first 160 characters of the message body | Nobody: customers write them | Not versioned | Injection and robustness cases |
| Model and settings | The model identifier and parameters | Esohe; the platform team | Pinned in the manifest | The full run |
Two rows matter more than they look. The handbook is edited by people who are not engineers, so the process must let them change it without waiting for you and must still put a run between their edit and a customer. And the tool results are text the model reads as readily as your rules, written by people you do not control. A business that puts instructions in a message body has written part of your prompt. The course chapter on guardrails and injection covers the defences, and the track’s chapter on guardrails, injection and abuse covers the test list.
The unit that ships is not a part. It is a release that names every part at once:
release: asst-2026-11-r3
rules: v12
handbook: 2026-10
tools: t4
model: <the pinned model identifier>
A release is what a customer’s conversation ran under. When someone asks what was live last Tuesday, this is the record that answers it. Moving production to another release is the deploy, and editing a part in place is never one.
Where the text lives, and who can edit it
Most teams settle on one of two homes. Files in the repository give you review, history and CODEOWNERS on the prompts directory, so a rule change gets the same pull-request review as the code that calls it. A registry or vendor console lets non-engineers edit without a deploy and moves production in seconds. The course chapter compares them in a table; the job-level point is that either one needs the same three things.
- A named owner for each part. At Wrenpost Esohe owns the rules and the support operations lead owns the handbook’s content. Ownership means you can refuse a change, and that the other person can see why.
- A path for non-engineers that ends at the gate. A handbook edit opens a pull request from a form: the text, the reason, the conversations that prompted it. The run happens automatically. The support operations lead sees the flips on conversations she recognises, and does not need to read a diff of tokens.
- No edit in place. If production can be changed without a new release name, you will one day be unable to say what it was running, and you cannot run a paired comparison without a baseline that still exists.
The Grok prompt incident that opens the course chapter is the third point failing at scale. Treat it as a reminder that your own handbook is one edit away from the same shape.
Read a diff for what it permits
A prompt diff is read differently from a code diff. In code you ask whether it does what it says. In a prompt you ask what the wording newly permits or forbids, and what the old wording was doing that nobody wrote down.
Words that set scope deserve a slower read than any others: always, never, only, any, every, unless, if. They tell the model how far to generalise. Swapping one for another changes the reach of a rule far beyond the sentence it sits in.
Take rule 9. Under “Always resend … when … failed, expired or undelivered”, the model reads the list of statuses loosely: if the customer wants a resend and the record looks broken, resend. Kenyan carriers return a status of rejected when a sender ID is not registered. The model treated “rejected” as one of the listed statuses, though the rule never named it. Once a customer registered the sender ID, resending was correct, and v12 did it. Under “Only …”, the model reads the list literally. rejected is not on it, so it declines. Three old cases passed under v12 because the word “Always” made the model generous, and nobody had written that duty down.
That is the usual shape of a prompt regression. The edit does what you intended. It also removes an accident that was holding something up.
The change-log entry
A change that reaches a customer carries a written entry. It is short, and it is written before the run, because a log written after the result is written to fit the result.
- The diff, verbatim. Old line and new line, not a summary.
- The failure and its evidence. Conversations, a count, a date range. Eleven conversations in four weeks, with their ids.
- The mechanism, or the words “not known”. A cause you can name: why did the assistant call the tool twice? If you cannot say, write that. A fix without a mechanism is a coincidence, and it will stop working when the model, the handbook or the traffic shifts.
- What the old wording did that nobody wrote down. You can rarely fill this in before the run. Leave it and come back to it once you have read the flips.
- Cases added before the change. The failure becomes a case first; see the week chapter.
- The run. Set size, number of runs per case, the noise floor, the flips, and the pass rate before and after.
- The decision and the way back. Ship, change, hold, or fix elsewhere, with a reason, and the release you would return to.
The entry has three readers. You, in six weeks, when the model is retired and you need to know why rule 9 says what it says. Support operations, who need to know whether the assistant will behave differently on conversations they handle. And the security lead, who needs to see any change to a tool that writes. A log that serves all three is a few lines, not a document.
The regression run
The statistics are in the course. What the role adds is the reading order.
Start with the noise floor. The evals in CI chapter shows how to measure it with an A/A run. At Wrenpost each of the 90 cases runs three times and counts as a pass if it passes at least two. The current version against itself flips two cases. That is the floor: a candidate that flips two cases has told you nothing.
Then read the flips, not the total. A table with one row per flipped case, showing what a correct answer must do and the result under each version, is the artefact. The totals go at the bottom. Candidate v13 passes 83 of 90 (92.2%) and v12 passes 82 (91.1%): a gain of one case. The table shows four fixed and three broken. An engineer who reads the total ships it. An engineer who reads the table sees that every broken case is a Kenyan sender-ID resend.
Look for clusters. Flips with a shared subject are not noise, even when there are only three of them and the noise floor is two. All three fail on all three runs under v13, all three share a country and a status, and a single word explains them. Scattered flips with no pattern are what noise looks like.
Then name the mechanism. For each cluster, write the sentence that explains it and test the sentence: add two or three neighbouring cases, such as a Kenyan resend with a still-unregistered sender ID, that should come out differently if you are right. A sentence you cannot test is a guess.
The evals in CI chapter shows how to automate the run and its thresholds, and building an eval set covers how many cases a claim needs. The set size of 90 is illustrative: it is what the set has grown to by this point in the example.
Prompt, code or context
Not every failure belongs in the prompt. Before editing a rule, decide which of three levers the failure needs.
- Code, when the action costs money or cannot be undone, or when the model is behaving reasonably on bad information. A rule makes a failure less likely; code makes it impossible. Anything the business cannot afford to get wrong belongs here.
- Context, when the model lacks something it needs: a field the tool does not return, a handbook paragraph that is out of date, a record that is stale. Giving it the missing fact is better than adding a rule that tells it to guess better.
- The prompt, for tone, judgement, ordering and what to do when the facts are unclear. Rules are cheap, they carry the assistant’s personality, and they are the right lever when sampled behaviour is acceptable.
Rule 9 shows the three at once. The double resend has a cause outside the model. lookup_message keeps returning failed until the carrier’s delivery report arrives, so a customer who writes “nothing yet” shows the model a message that still looks resendable. The model is behaving reasonably on a stale record. The robust fix is in the tool: resend_message refuses a second resend of the same message within 24 hours and returns the reference of the first. Anthropic’s own prompt-engineering guide says that not every failing eval is best solved by prompt engineering, and it puts success criteria and a way to test them ahead of the prompt. A tool guard is also testable on its own, with ordinary unit tests.
Context is code too
Three more habits belong to context as a whole.
Every rule has a price. The context is finite, and Anthropic’s engineering write-up on context engineering recommends the smallest set of high-signal tokens, and a system prompt at the right altitude: not brittle hard-coded logic, not vague guidance. Rules accumulate because adding one is easy and nobody deletes. Give each rule at least two cases, and once a quarter delete the rules whose cases pass without them.
Order is a cost decision. The model’s cache matches an exact prefix, in the order tools, system prompt, then messages, and a change at one level invalidates that level and everything after it. Anthropic’s prompt-caching documentation says this directly, and the lesson on the prompt cache prefix shows the cost. A change to a tool description invalidates the lot. A change to the rules invalidates the rules, the handbook and the conversation. Put what changes rarely first, and treat a tool-description edit as the expensive change it is.
Tool results are untrusted input. The 160 characters of message body that lookup_message returns go to the model with no labelling unless you add it. Mark them as data in the tool result, test them with the injection cases, and treat a change to what a tool returns as a context change that needs a run.
Where practitioners disagree
Git or a registry. Teams that keep prompts in the repository get review for free and give up fast edits. Teams with a registry get speed and have to build the gate into promotion. Both work. The failing combination is a registry that lets anyone promote a version without a run.
Few principles or many rules. One school writes short principles and trusts the model’s judgement, in the spirit of “the right altitude”. Another writes numbered rules, one behaviour each, because rules can be tested one at a time. Numbered rules are easier to attach cases to. Principles are shorter and generalise further, and fail in ways that are harder to localise.
Edit continuously or freeze. Support operations wants handbook changes live the same day. Engineers want a weekly window. A same-day path with a run under an hour usually satisfies both, as long as the run is automatic and the owner of the handbook can read the flips.
Prompt-only fixes. A prompt change takes minutes and a tool change takes days, which is why prompts get patched. A reasonable rule: patch in the prompt when sampled behaviour is acceptable and the cost of a miss is small; guard in code when the cost of one miss is a billable send.
Day to day
A week for an AI engineer who owns the assistant’s rules, with a support operations lead who owns the handbook and a product manager for support tooling.
- Monday. The read of real conversations. Anything that looks like a change becomes a case before it becomes a fix; the week chapter has the details.
- Tuesday to Thursday, as requests arrive. Handbook and rule changes come in as pull requests from a form. Each gets a release candidate name such as
r4-c1, an automatic paired run (under an hour for 90 cases at three runs each, illustrative), and a change-log entry before anyone replies. Hand the support operations lead the flips on conversations she knows. - Wednesday. Eval day: new cases from the week’s read, with neighbours, and the cluster hunt on any run that moved.
- Thursday, 15 minutes. The change review with support operations and the product manager: which candidates are ready, which are held, and what is deliberately not changing. Tool changes go to the security lead before they ship.
- Friday. Cut the release, update the manifest, check that the rollback release still loads.
Monthly. Read the manifest history against the complaints. Check every rule still has two cases, and delete the ones that do nothing. Quarterly. Read the whole prompt, top to bottom, as a new engineer would, and note every sentence you cannot explain. When the provider announces a model retirement, the model change goes through the same gate; the track’s chapter on model upgrades and regressions covers it.
When it breaks. A customer is being told something false. Roll the pointer back to the last release, which is configuration, not a deploy. Then work out which part of the bundle changed, with the manifest.
One engineer owns the prompt and a founder edits it between meetings. Keep it in the repository as a file with a version in its name, and keep the cases in a spreadsheet you rerun before anything reaches customers. A change log can be one line per change in a text file. Do not build a registry or a release manifest. The two habits that matter at this size are a name for what is running and a run before each change, because otherwise you cannot tell which edit broke what.
Edits arrive from several hands: support rewrites the handbook, a product manager adds a rule, another team copies your prompt. This is where the parts and their owners must be written down. Add the release manifest, a pull-request form for non-engineers and an automatic run, and train one support lead to read flips. Set a rule that tool changes go to security. The risk is that you become the only person who can tell a safe edit from an unsafe one, and every edit queues behind you.
A platform team, a model-risk review and a change board all want a say, and prompts sit inside existing change processes. Your change-log entry and run become the evidence those forums ask for, so keep them readable by a stranger. Expect separate owners for the rules, the handbook and each tool, across teams, and agree who signs a release. Keep a rollback release loadable at all times, and share the read of conversations across people so one reader does not decide what counts as a failure.
Template
# Change log: <old version> to <new version> · <date> · author <name>
Release: <release name> · Parts: rules <v>, handbook <date>, tools <v>, model <id>
## What changed
<old line> → <new line> (verbatim)
## Why
Failure and evidence: <count, span, conversation ids>
Mechanism: <the cause you can name, or "not known">
## What the old wording did that nobody wrote down
<fill in after reading the flips>
## Cases added before the change
<ids and what a correct answer does>
## Regression run (<n> cases, <k> runs each, pass = at least <m> of <k>)
Noise floor (old version against itself): <n> flips
| Case | Slice | A correct answer… | Old | New |
|---|---|---|---|---|
Fixed <n> · Broken <n> · Unchanged <n> pass and <n> fail
Pass rate: old <x>% · new <y>%
## Read of the flips
<clusters, the sentence that explains each, the test of that sentence>
## Decision
<ship / change / hold / fix elsewhere> because <reason>. Return to: <release>.
Follow-up: <owner, date> WORKED EXAMPLE
Wrenpost is a fictional messaging API: about 180 staff, 55 engineers, about 2,400 business customers. Esohe owns its support assistant, which handles about 700 conversations a week (illustrative). Damisa, a support agent who handles Kenyan accounts, wrote the Kenyan sender-ID cases.
Change. Rule 9, “Always resend a message …” to “Only resend a message …”, in candidate v13 against RULES v12. Why. 11 conversations in four weeks (of about 2,800) called resend_message twice for one message. Mechanism. Not known when written; later filled in as a stale failed status in lookup_message. Run. 90 cases, three runs each, pass at two of three. The noise floor, v12 against itself, is 2 flips.
| Case | Slice | A correct answer… | v12 | v13 |
|---|---|---|---|---|
| R-03, R-05, R-08, R-11 | Double resend | Reports the status; does not resend again | fail | pass |
| K-04, K-07, K-11 | Kenyan resend | Status rejected, sender ID now approved: resends once and says so |
pass | fail |
Fixed 4, broken 3, unchanged 83 (79 pass both, 4 fail both). Totals: v12 passes 79 + 3 = 82 of 90, 91.1%; v13 passes 79 + 4 = 83, 92.2%. Read. The three breaks all fail three runs of three, share a country and a status, and a single word explains them: “Only” makes the model read the status list literally and rejected is not on it. That is the duty the old wording carried unwritten. Decision. Hold v13; keep v12 live. Ask Routing for a 24-hour guard in resend_message, add four neighbouring Kenyan cases, and return to v12 as the release to roll back to. Follow-up: Esohe, this sprint.
Now you
You are Seraphina, an engineer on Wrenpost’s assistant team, and you own the change log this month. The support operations lead has edited the handbook to add a paragraph (about 380 tokens, taking HANDBOOK 2026-10 from 6,000 to 6,380) telling the assistant to offer a callback from a support agent whenever a customer mentions a charge. She wants it live today. RULES v12 stays as it is. You run the 90-case set, three runs each, pass at two of three. The current version against itself flips 1 case. The candidate, HANDBOOK 2026-11, fixes five: B-02, B-05, B-09, B-12 and B-14 are billing complaints, where a correct answer offers a callback. It breaks two: D-03 and D-07 are developer questions with curl and JSON, where the response contains a field named "charges" and a correct answer reads the JSON; the candidate offers a callback instead. Seventy-nine cases pass on both versions and four fail on both. Write the change-log entry and the regression table, recompute both pass rates, and decide.
Self-check
Esohe's RULES v13 changes one word in rule 9, 'Always' to 'Only'. Eleven conversations in four weeks, of about 2,800, had resend_message called twice for one message, each an extra billable SMS refunded by hand. The run on the 90-case set fixes four cases and breaks three, all Kenyan sender-ID resends that Damisa wrote. The cause of the double resend is that lookup_message still shows 'failed' until the carrier's delivery report arrives. What does Esohe do?
- POST Effective context engineering for AI agents Anthropic, 2025
Treats context as a finite resource and gives guidance on system prompts and tool descriptions, including aiming for the right altitude and starting minimal. Read it before you add your next rule.
- DOC Prompt caching Anthropic
States that a cache hit needs an identical prefix, in the order tools, system, messages, and that a change at one level invalidates that level and all after it. It is the reason edit order is a cost decision.
- DOC Prompt engineering overview Anthropic
Puts success criteria and a way to test them before prompting, and says not every failing eval is best fixed by prompt engineering. Use it when deciding which lever a failure needs.
- POST Your AI Product Needs Evals Hamel Husain, 2024
A practitioner's account of building unit-style tests and reviewing traces so that every change is measured. It is the background to the regression run in this chapter.
- POST What We Learned from a Year of Building with LLMs (Part II) Eugene Yan, Bryan Bischof, Charles Frye, Hamel Husain, Jason Liu and Shreya Shankar, 2024
The operational half of six practitioners' lessons, with a section on working with models that covers versioning, pinning and migrating prompts across them.
All companies and people in these examples are fictional. Any resemblance to a real business or person is unintended.