Skip to main content
Technical Enough
Next: Output your code can use

Write the prompt as a spec, not a sentence

Chapter 4 of 10 in Add AI Features · 18 min

The evening after you connect your first call, you sit down to run real inputs through it, and the replies read as if they came from someone else's app. You send your test input at 9:47 pm, and the reply comes back in about two seconds: 176 words that open with "Certainly! I'd be happy to help," answer a question no user asked, and end by offering three follow-ups. You scroll up to the prompt you sent, a single sentence, and you can work out that the problem is in the request, not the reply: it never said who reads the reply, what the limits are, or what form the reply should take, so the model filled each of those gaps with the most common pattern in its training data, the huge collection of text used to build the model.

After Make your first model call, your feature is in the same state as in the scene above: the connection works, and what comes back now depends on the instructions field. Our family nutrition app FuelTheFam was at the same point with its fridge feature: a parent photographs their open fridge, the photo goes to a multimodal model (one that accepts images as well as text), and a shopping list comes back while they wait. You have already read the instructions that feature runs on today, in the request printed in that chapter; this chapter tells how we turned three vague lines into them.

The first fridge prompt, printed in full

Here is the complete prompt our first working version ran on:

You are a helpful assistant.
Look at this photo of a fridge and tell me what groceries we need.
Be accurate and helpful.

And here is what the model produced from it for a real photo of our own fridge, with milk, eggs, butter, and spinach visible on the shelves:

Sure! From the photo it looks like you have milk, some eggs,
butter, and possibly some leftovers in a container. A well-stocked
family fridge usually also has yogurt, cheese, and fresh fruit,
so I'd suggest picking up yogurt, cheddar, apples, and orange
juice. Would you like a simple meal plan built around these?

Read it as the parent would, and each flaw costs something. The list is padded with yogurt, cheddar, apples, and orange juice, none of them in the photo; they appear because a typical fridge holds them, so a parent shopping from it buys food the photo never showed. The reply hedges with "possibly some leftovers," and it ends with a question on a screen that gives the parent no way to answer. Nobody on our team reads a list before the user sees it, so this block, exactly as printed, is what a user would have seen.

Why the model fills gaps with the most common answer

The objection goes like this: a model trained on a huge share of the written internet should not need step-by-step instructions for a shopping list. The printed reply shows that it does: for every question our three lines left open, the model produced the most common reply.

  • Who reads this? Our prompt did not say, so the model produced a chat reply, complete with an opening line and an offer to help further.
  • May items appear that the photo does not show? Our prompt did not say no, so the model filled out the list the way shopping lists in its training data usually look.
  • What must the reply look like? Our prompt did not say, so the model produced the most common form: a friendly paragraph offering more help.

The model fills every gap in a prompt with the most common pattern in its training data, so anything your prompt leaves out gets that most common pattern instead of the choice you would have made.

Our rewrite, one part at a time

Here is the fridge prompt as it runs today, complete:

You write the shopping list for the FuelTheFam fridge feature.
A parent has photographed their open fridge and is waiting on
this screen; your reply becomes the list they see.

Rules:
- List only items visible in the photo. Never add an item
  because a typical fridge would have it.
- If the photo is too dark or blurry to read, reply with the
  single word RETAKE and nothing else.
- No greetings, no advice, no questions.

Example
Photo shows: a milk carton, six eggs, wilted spinach.
Reply:
milk
eggs
spinach

Photo:

With this prompt, the same fridge photo gets this reply:

milk
eggs
butter
spinach

We wrote every part of the rewrite to fix one of the failures printed above, so match each part to its failure rather than memorizing categories.

  • The role, the first two lines. They skip "you are an expert," which carries no information, and state who reads the reply and where it appears; once we stated those two facts, the model stopped producing chat.
  • The boundaries, the Rules block. We wrote the visible-items-only rule to stop the padding; the RETAKE rule for a photo taken one-handed into a dark fridge, so the feature asks for a retake instead of guessing; and the no-greetings rule to cut the "Sure!" a waiting parent would have to scroll past.
  • The example. It shows the format instead of describing it; the next section shows why that works better than adjectives.
  • The input slot, the final line. The photo is attached after the instructions and kept separate from them, so the instructions and the user's input never get mixed together.

The drawing labels the parts of a prompt with the names you will meet in documentation, using a bike shop's support prompt as its example. SYSTEM is the role line: the role the model plays and its job. TASK says exactly what to do, EXAMPLE shows one good answer, RULES set limits and format, and INPUT is the user's data. Our fridge prompt states its task inside the role lines, so it has no separate TASK line.

The five parts of a promptA prompt shown as five stacked parts: a system line that sets who the model is and its job, a task that says what to do exactly, an example that shows one good answer, rules that set limits and format, and the input, which is the user's data. Caption: a prompt is a spec you write and revise, not a magic phrase.ONE PROMPT, FIVE PARTSWHAT EACH PART DOESSYSTEMYou are a support agent for a bike shop.who it is, and its jobTASKAnswer in two or three sentences.what to do, exactlyEXAMPLEQ: lead time? A: about two weeks.show one good answerRULESNever invent a price. If unsure, say so.limits and formatINPUT{ the customer's message }the user's dataA prompt is a spec you write and revise, not a magic phrase.

A prompt is a specification (a spec) you write and revise, like a brief for a contractor: it states the role, the boundaries, one worked example, and the format, and you improve it by revising it rather than by hunting for a magic phrase.

One worked example controls the format better than adjectives

We added the example block only after a failed attempt worth showing. First we tried to control the format by describing it, with one added rule: "Keep the list clean, concise, consistent, and easy to scan." One run returned • Milk (1 carton), the next returned - eggs, about 6, each arguably clean and concise, and no two runs matched. An adjective describes a standard without settling any single choice: bullets or none, capitals or not, counts or not. We replaced that sentence with the three-line example, and from the next run on, the replies came back in one format: lowercase, one item per line, no bullets, no counts, exactly as the example showed. An example works better than a description because it gives the model the standard itself instead of words about it. Each fridge list costs us well under a cent, so checking the fix across ten reruns cost a few cents.

Keep the prompt in your project as a file, like code

The fridge prompt is a file in the FuelTheFam repo (a repository, the project folder that git tracks), and git saves every version of it like every other file in the project. So every change is a diff, a record of exactly what changed, with a date and an author, instead of someone's memory of what they typed into a provider's console (its web page for running calls). That habit is what makes revising possible: when a rule stops working, the fix is a changed line in the file, and you prove the fix by rerunning the same inputs. Revising the prompt is also the first rung of the customization ladder, the order this part follows for changing what a model does, from the cheapest change to the most costly: revise the prompt before you hand the model your data, hand it data before you hand it tools, and leave fine-tuning, training a model further on your own examples, until you have tried every cheaper rung.

One limit is worth stating here. The model produces a response to whatever it is sent, so a clear prompt lowers how often bad output appears without ruling it out, and a user can type input that pushes the model past your written rules. That is why anything that must never appear is checked in code as well as written in the prompt.

Try it now

This drill takes about fifteen minutes; the no-setup path costs nothing and the path with tools costs a few cents. You bring what the last drill produced: your feature's first working call from Make your first model call, or the request on paper if you took that chapter's no-setup path. You leave with Prompt v1 for your feature, saved in your project, with the before and after outputs kept next to it. Call the rewrite v1 because it is the first version saved as a file.

No setup: Write the vague three-line version of your feature's prompt, the way ours started, and note in the margin what the model would likely pad the reply with, where it would hedge, and what chat it would wrap around the answer. Then rewrite it following our printed rewrite: two lines stating who reads the reply and where it appears, boundary rules including one for unreadable input (your equivalent of RETAKE), one worked example of a perfect reply, and the slot where the user's input is attached. For the running club's support assistant, the vague version is "You are a helpful assistant for a running club. Answer the member's question." The rewrite says that a signed-in member reads the reply in a chat box on the club's site, limits the answer to the club's facts pasted into the prompt, and gives the exact sentence to reply with when those facts do not contain the answer: "I don't have that answer. Please write to help@runclub.example and a person will reply within 48 hours." Keep both pages; they become the file as soon as you have tools.

With your tools: In your project, ask Claude Code to move your feature's prompt into a file of its own, then run the same real input through the vague version and the rewrite, and save both outputs next to the file. Read the pair side by side; you should be able to trace most differences to a line you added, and the rest are the run-to-run variation from Make your first model call. Same move in Codex or Cursor: create the prompt file in the sidebar chat and rerun the call both ways. If nothing is installed yet, the Setup Clinic gets you running.

Chapter Summary

  • A vague prompt does not produce a broken reply; it produces an average one, because the model fills every unanswered question with the most common pattern in its training data.
  • Given our fridge feature's three vague lines, the model padded the list with items not in the photo, hedged on what it could not read, and wrapped the answer in chat.
  • The rewrite fixed each failure with a specific part: a role stating who reads the reply and where it appears, boundary rules, one worked example, and a separate slot for the user's input.
  • Flattery like "you are an expert" carries no information; a useful role line states who reads the reply and where it appears.
  • One worked example fixed the fridge list's format where a sentence of adjectives could not, because an example gives the model the standard instead of describing it.
  • The prompt lives in your repo as a file, and git saves every version, so every change is a diff you can read, test, and undo.
  • A prompt lowers how often bad output appears without ruling it out, so anything that must never happen is also enforced in code.
  • From here on, your drill artifact is Prompt v1 for your feature, saved in your project with its before and after outputs.
  • Next, in Get output you can build on, you turn the reply from clean lines a person can read into a structure your code can parse every time.

Sources

  • Anthropic prompt engineering documentation (last verified July 2026).
  • OpenAI prompt engineering guide (last verified July 2026).
  • Google Gemini prompting strategies documentation (last verified July 2026).
  • FuelTheFam (fuelthefam.com), our family nutrition app; the fridge prompts and outputs are quoted from our build.
Reaching the end does this for you.
Next upGet output you can build onChapter 33 of 38 · 18 min
Glossary
Prompt engineering