Notes
The idea
Here is the mental model. Picture a very smart colleague on their first day. They have read a huge amount, but know nothing about your product, your users, or what good looks like to you. The prompt is your brief to them, and it is all they get. Whatever you leave out, they will guess. Prompt engineering is mostly the skill of not leaving the important things out.
- the model has read a lot, but knows nothing about
- your product, your users or what "good" means to you
- a prompt is a brief for a smart new colleague on their first day
- whatever you leave out, it will guess
Anatomy
A good prompt has up to six parts. A role and goal, saying who the model is and what success means. Context, the facts and documents it needs. The task, the one specific job. Constraints, like length, tone and what to do when unsure. The output format, the exact shape of the answer. And examples, a few samples of good output. A quick question needs two of these. A production feature usually needs all six.
- 1 role + goal: who it is, what success means
- 2 context: facts, documents
- 3 task: the one job to do
- 4 constraints: length, tone, what to do when unsure
- 5 output format: exact shape
- 6 examples: one to three
- not every prompt needs all six
System vs user
Chat APIs give you two main places to write. The system prompt is written by you and stays the same on every call. It holds the role, the rules, the format and the tone. The user message changes every call, the actual question or document. Models are trained to give system instructions more weight. But that is a strong hint, not a security wall, so never rely on it alone to protect secrets.
- system prompt written by you, same on every call: role, rules, format, tone
- user message changes every call: the question, the document
- user text never overrides
- your rules by being louder
A weak prompt
Let us work an example. The job is to summarise support tickets for the on call engineer. The weak prompt is one line. Summarise this support ticket, then the ticket. Run it three times and you get five paragraphs, then a bullet list, then a polite reply to the customer. None of them says how urgent it is, and the error code got paraphrased away. The model did nothing wrong. It was never told what the summary is for.
Summarize this support ticket:
[ticket text pasted here]
result, three runs:
run 1: five paragraphs
run 2: a bullet list
run 3: a polite reply
to the customer
no severity, error code lost A strong prompt
Now the strong version, for the same model and ticket. A role, you triage tickets for on call engineers. A goal, they must decide what to do in thirty seconds. The ticket inside tags. Then the task, three constraints, and a fixed format: severity from P one to P four, three bullets, one next step. Each line removes a guess. Now three runs give the same shape, with the error code intact.
You triage tickets for on-call engineers.
Goal: they decide what to do in 30 s.
<ticket>{ticket_text}</ticket>
Summarise the ticket above.
- at most 3 bullets, plain English
- copy error codes exactly
- missing info: write "unknown"
Format:
Severity: P1-P4
Summary: <bullets>
Next step: <one line> Clear beats clever
You will see lists of magic phrases online. You are the world's best expert. This is extremely important. All caps. Promising a tip. On modern models these do little, and shouting can make a model over apply a rule everywhere. What works is being specific. Say who reads the output and why a rule exists. Replace adjectives with numbers. Short becomes under sixty words. Clear beats clever, and it keeps working when you upgrade the model.
- weak tricks "you are the world's best" "this is very important!!" ALL CAPS, threats, tips
- what works say who reads the output say why a rule exists give numbers, not adjectives "short" → "under 60 words"
Say what to do
Tell the model what to do, not just what to avoid. Do not use markdown is weaker than write in plain paragraphs of flowing prose. Do not be too long is weaker than answer in two sentences. A don't still puts the unwanted thing in front of the model, and leaves the right behaviour to chance. Keep genuine prohibitions, like never reveal another customer's data, but pair each one with what to do instead.
- don't: "Don't use markdown."
- do: "Write plain paragraphs of flowing prose."
- don't: "Don't be too long."
- do: "Answer in 2 sentences."
- a "don't" names the thing
- you do not want, and leaves
- the alternative to chance
Allow I don't know
Models are trained to be helpful, so when the answer is missing they tend to produce something plausible anyway. Give them an honest way out. Answer only from the documents. If the answer is not there, reply exactly, not in the documents. A fixed phrase like that is easy for your code to detect, so you can show a fallback or route to a person. This one line removes a large share of made up answers in question answering features.
- without it: question not in the docs → a confident invented answer
- with it: "Answer only from the <docs>. If the answer is not there, reply exactly: Not in the documents."
Output format
Be exact about the output format, because often your code reads it, not a person. Name the fields, their order and their labels. Show one filled in sample. Say what to write when a field is unknown, so the model does not invent a value. When a program must parse the result, ask for JSON and validate it. Episode three of this unit covers structured output modes that make valid JSON close to guaranteed.
- say the shape: fields, order, labels, length
- show one filled-in sample
- say what to output when a field is unknown
- if code parses it: ask for JSON, validate it, or use a schema mode (episode 3)
Iterate with evals
How do you know a prompt got better? Not by trying two inputs and squinting. Build a small eval set, say thirty real tickets with the severity a senior engineer picked. Version one scores twenty one of thirty, seventy percent. Adding the role and format gives twenty six, about eighty seven percent. The unknown rule gives twenty seven, ninety percent. Change one thing at a time and rerun every case, because a fix for one input often breaks another.
30 real tickets + expected severity v1 weak prompt 21/30 70% v2 + role, format 26/30 87% v3 + "unknown" rule 27/30 90% grade: code checks first (format, severity match), a model judge for tone run each case 3x if sampling
Version prompts
Treat prompts as code. Keep them in files in your repository, reviewed like any other change, not edited live in a console. Give each version an id and log it with every model call, so when users report bad answers you know which prompt produced them. Run the eval set before merging. Roll new prompts out gradually and keep rollback to one step. And pin the model version, because a model upgrade changes behaviour just like a prompt edit does.
- keep prompts in files, in git, not in a web console
- each version has an id
- log prompt id with every call and its output
- evals run before merge
- roll out gradually, roll back in one step
- pin the model version too
Common mistakes
The usual mistakes. Assuming the model knows things it was never told. Rules that contradict each other, like be brief and be thorough, so the model picks one at random. One giant prompt doing five jobs, when a chain of small prompts would be easier to test. Patching each bad output with a special case rule and never rerunning the tests. No fixed format, then fragile parsing. And putting secrets in a system prompt, which users can often coax out.
- assuming context the model never got
- rules that contradict each other ("brief" + "detailed")
- one giant prompt doing five jobs: split into steps
- fixing one bad output with a special-case rule, untested
- no format, then regex hell
- secrets in the system prompt
Numbers worth knowing
Some ballparks. A token is roughly three quarters of an English word. A production system prompt is often five hundred to five thousand tokens, and it is sent on every call, so its size matters. Start with twenty to fifty eval cases and grow toward hundreds as you collect real failures. One to three examples usually set the format. Output tokens typically cost three to five times input tokens. Keeping the long stable part first lets prompt caching reuse it cheaply.
1 token ~ 3/4 of an English word chat question ~ 20-200 tokens prod sys prompt ~ 500-5,000 tokens first eval set ~ 20-50 cases mature eval set hundreds to thousands examples 1-3 usually enough output tokens ~ 3-5x price of input a long stable prefix is cheap to reuse with prompt caching
Say it like this
How to say it. The system prompt sets the role, the goal, the rules and an exact output format. Documents go inside tags with the question last, and the model is told to answer unknown rather than guess. Prompts live in git with version ids that we log on every call. Every change runs against a fifty case eval set and only ships if the score holds or improves. That shows you treat prompting as engineering, not wordsmithing.
- "The system prompt sets role, goal, rules and an exact output format. Documents go in tags, question last. It may answer 'unknown'. Prompts live in git with ids; every change runs a 50-case eval and ships only if the score holds."