Skip to Content

Testing prompts with evals

One lucky try is not proof that a prompt works. Watch a clinic's message sorter pass a hand test and fail a real patient, then build a small test set, a grader and a score, and catch a new bug the moment a fix creates it.

11 minFree

Testing prompts with evals
  1. Write
  2. Run
  3. Grade
  4. Score
  5. Change
FIG. PE-EVALUATION / 07 PARTSYouprompt writerPatientsreal messagesPromptv1, then v2Test set8 cases + answersModelany LLMGradercode or a modelScoreboardscore per version

Press Play to watch it run, or step through with ← →. Then switch to Practice and run it yourself.

00/07
You sort messages sent to the front desk of Sunrise Clinic.
Pick exactly one label: APPOINTMENT, REPORT, BILLING, URGENT, OTHER.
Reply with the label only.

Message: {{MESSAGE}}

Eval results

No results yet. Press Play.

Background: the idea in plain words1 min read

You write a prompt. You try it with one message. The answer looks right. Is the prompt good?

You do not know yet. You know it worked once, on a message you happened to think of. Real users send messages you did not think of. And a model's output is not fully deterministic (the same input can give a different output on another run), so even "it worked once" is weaker than it sounds.

An eval (short for evaluation) is a repeatable test for a prompt. It has three parts:

  • A test set. A list of inputs, each with the result you expect. Each item is called a test case.
  • A grader. Something that decides if an output is right. It can be a line of code, a person, or another model.
  • A score. One number for each version of the prompt, such as "6 of 8 passed", plus the list of cases that failed.

With these three, a change to the prompt stops being a matter of opinion. You run the same set again and compare two numbers. Anthropic's prompt engineering guide lists this as a prerequisite: before you tune a prompt, have clear success criteria and a way to test against them.

The running example is the front desk of a clinic. Patients send WhatsApp messages, and a prompt sorts each one into a label: APPOINTMENT, REPORT, BILLING, URGENT or OTHER. One message says: "Chest pain since morning. Can I come on Friday?" The prompt files it as an ordinary appointment. In the first scenario, a patient finds that bug. In the second, your test set finds it first.

Press Play to see the try-once approach fail. Then switch Try it to the test set, and then to the third scenario, where a model does the grading.

What to notice

  1. One good answer proves very little. The easy message passed in every scenario. The failures were hiding in messages that mix two things, and you only see those if you go looking.
  2. The test set comes before the fix. You measured prompt v1 first and got 75%. Without that baseline (the starting score), you could not say that v2 was an improvement.
  3. Use code to grade when you can. Comparing a label with the expected label is one line, runs instantly and never changes its mind. The prompt asked for "the label only" partly so that this would be possible.
  4. A fix can break something else. The new URGENT rule fixed two cases and broke a third that used to pass. This is called a regression. You only caught it because you re-ran all eight cases.
  5. A model grader needs grading too. For tone and other matters of judgement, a second model can grade with a rubric. Check it against your own verdicts before you trust it.
Go deeper

Three ways to grade

1 min read
GraderGood forLimits
CodeLabels, numbers, formats, "does the answer contain this phrase"No nuance. Cannot judge tone or helpfulness
A personAnything, including subtle qualitySlow and expensive. Does not scale
A model with a rubricTone, completeness, following a policyAn extra model call per case. Can be wrong, so test it first

Anthropic's guide says to choose the fastest, most reliable, most scalable method that fits. It describes code-based grading as the fastest and most reliable, human grading as the most flexible but slow and expensive, and model-based grading as fast and flexible once you have tested that it is reliable.

For a model grader, both Anthropic and OpenAI give similar tips:

  • Write a detailed rubric. Say exactly what makes an answer correct or incorrect.
  • Ask for a fixed verdict. "correct" or "incorrect" is easy to count. OpenAI's guide says pass or fail judgements are more reliable than open-ended numeric scores.
  • Let the grader reason first, then give the verdict.
  • Calibrate against people. Compare the grader's verdicts with human labels, and scale up only when they agree consistently.

OpenAI's guide also warns about known weak points of model judges, such as favouring longer answers.

Go deeper

Building a test set that finds real bugs

1 min read

A test set of only easy cases gives a high score and a false sense of safety. The guides agree on what to put in:

  • The real mix of your task. Anthropic's guide says to mirror your real-world task distribution. OpenAI's guide warns against data sets that do not reflect real traffic.
  • Edge cases. Anthropic lists irrelevant or missing input, very long input, and ambiguous cases where even people would disagree. In the clinic set, case 8 is junk and cases 5 and 7 are ambiguous on purpose.
  • Every failure you find. When a real message goes wrong, add it as a new case. OpenAI's guide recommends logging everything so that real traffic can be turned into test cases, and growing the set over time.

On size, Anthropic's guide says to prefer volume: more cases with automatic grading beat fewer cases graded carefully by hand. Eight cases fit on a screen for this lesson. A real set is larger and keeps growing.

When to run the whole set again After every change to the prompt, however small. After changing the model or its settings. And when your vendor updates the model: OpenAI's guide notes that even different snapshots of the same model family can give different results, and recommends building evals so you can watch your prompt's behaviour as you change versions.

Go deeper

What an eval costs

1 min read

Every case is at least one model call, and a model grader adds a second. So a full run costs tokens and takes time, and both grow with the size of the set. This is one more reason to grade with code where possible. It is still far cheaper than a wrong label reaching a patient.

Each vendor also offers its own tools for running evals, and these products change over time. The method does not depend on them. A file of cases, a short script and a score written next to each prompt version work with any model.

Go deeper

Words to know

1 min read
WordMeaning in simple words
EvalA repeatable test for a prompt: fixed inputs, a grader and a score
Test caseOne input together with the result you expect for it
GraderThe thing that decides if an output is right: code, a person or a model
RubricA written marking scheme that tells a grader what counts as correct
BaselineThe score of the current prompt, measured before you change anything
RegressionA case that used to pass and fails after a change

Check your understanding

1. You tried your prompt on one message and the answer was right. What do you actually know?
2. Your prompt returns one label from a fixed list. Which grader should you reach for first?
3. A change to the prompt fixed the two failing cases. Why run the other six again?
Sources: the official documentation4 links

Something wrong or unclear in this lesson? Tell us, it gets fixed.