The short answer
#A prompt is code. It has behaviour, it has edge cases, and a one-word change can break something three features away. So test it like code: build a small set of real inputs with expected outputs, write a script that runs them through your prompt and scores the results, and run that script on every change in CI. Where the output is structured, check it exactly. Where it is free text, use a second model with a written rubric as the judge. Keep the prompt in git next to the tests.
_10[_10 { "id": "refund-1", "input": "I want my money back, the app crashed twice", "expected": { "category": "refund" } },_10 { "id": "bug-3", "input": "Login button does nothing on Safari", "expected": { "category": "bug" } },_10 { "id": "other-2", "input": "Do you have a careers page?", "expected": { "category": "other" } }_10]
Why it matters
#Prompts fail in ways ordinary code does not. The output is not deterministic, so a change can make the model worse on 10% of inputs while every example you tried by hand still looks fine. The failures are silent: a classifier that starts filing refunds under "other" will not throw, it will quietly misroute tickets. And prompts drift. Someone adds a line for one awkward customer, and a month later nobody knows why the summaries got longer.
Spot checks do not catch this, because you only try the inputs you happen to think of, and different ones each time. An evaluation set fixes the inputs so comparisons are fair, and automation means the check actually runs. The goal is the same as a unit test suite: a fast, repeatable answer to "did I just make this worse?"
How to do it
#Build a set of real inputs
Start with twenty to fifty cases. Pull them from real traffic where you can: support tickets, user questions, documents your app actually processes. Include the easy majority, the awkward edge cases, and a few inputs where the right answer is to decline. For each, write the expected output, or at least the properties it must have. Store them as JSON in the repo with an id so a failure is easy to find.
Fifty cases will not catch everything, but it catches regressions, and it grows. Resist generating the whole set with a model; synthetic inputs are tidier than real ones, and the tidy cases are not where prompts break.
Check structured output exactly
When the output is a category, a boolean, a list of IDs or a JSON object, compare it directly. This is cheap, deterministic and unarguable. Use structured outputs so the shape is guaranteed and your test only needs to check the values.
_10const result = await classify(testCase.input);_10expect(result.category).toBe(testCase.expected.category);
For extraction tasks, check the fields that matter; for lists, compare as sets if order is not meaningful.
Judge free text with a rubric
For summaries, replies and explanations there is no single right answer, so ask a model to grade against a rubric you wrote. Keep the rubric concrete ("mentions the refund deadline", "under 80 words", "does not promise anything the policy does not") and have the judge return a pass or fail with a reason. Use a strong model for the judge, and a different prompt from the one under test.
_12const Verdict = z.object({ pass: z.boolean(), reason: z.string() });_12_12async function judge(input: string, output: string, rubric: string) {_12 const res = await client.messages.parse({_12 model: 'claude-opus-5-5',_12 max_tokens: 512,_12 system: 'You grade answers against a rubric. Be strict: pass only if every point is met.',_12 messages: [{ role: 'user', content: `Rubric:\n${rubric}\n\nQuestion:\n${input}\n\nAnswer:\n${output}` }],_12 output_config: { format: zodOutputFormat(Verdict) },_12 });_12 return res.parsed_output;_12}
Spot-check the judge's verdicts by hand when you first set it up. A judge that passes everything hides problems behind a green tick.
Run it in CI with a budget
Wire the set into your normal test runner so it runs on every pull request that touches a prompt. Each run costs real money, so give it a budget: cap the number of cases with an environment variable, and run the full set nightly through the Batches API if the per-PR run is a sample. Assert on the pass rate rather than every case, so one flaky input does not block a merge.
_18import { describe, it, expect } from 'vitest';_18import cases from './cases.json';_18import { classify } from '../src/classify';_18_18const limit = Number(process.env.EVAL_LIMIT ?? cases.length);_18const results: boolean[] = [];_18_18describe('ticket classifier', () => {_18 it.each(cases.slice(0, limit))('$id', async (c) => {_18 const out = await classify(c.input);_18 results.push(out.category === c.expected.category);_18 });_18_18 it('passes at least 90% of cases', () => {_18 const rate = results.filter(Boolean).length / results.length;_18 expect(rate).toBeGreaterThanOrEqual(0.9);_18 });_18});
Give the file a generous testTimeout, since each case is a network call.
Track the pass rate and keep a held-out set
Record the score for each run somewhere you can chart it: a CSV in the repo, a database row, a CI artifact. A pass rate that drifts from 96% to 88% over six small changes is the kind of regression nobody notices one PR at a time. Keep a second, smaller set that you never look at while editing the prompt. If the main set passes and the held-out set drops, you have tuned the prompt to your examples rather than to the problem.
Grow the set from production
Log the inputs your app receives (with consent, and without personal data you do not need) and review a sample each week. Every misclassification a user reports becomes a new case with the correct expected output. Over a few months the set turns from a sanity check into a real description of the job.
Version prompts in git, not a dashboard
Keep the prompt text in a file in the repo, imported by the code that uses it, so a prompt change is a diff in a pull request with the eval run attached. Dashboards that let you edit a prompt in production give you no review, no history and no test run, which is how silent regressions happen.
_10// src/prompts/classify.ts_10export const CLASSIFY_SYSTEM = `You sort incoming support tickets into exactly one category._10Categories: refund, bug, feature_request, other._10Choose "other" when none of the rest clearly fits.`;
Common pitfalls
#- Testing with the examples in the prompt. If your few-shot examples are also your test cases, the test proves nothing. Keep them separate.
- Judging with the same prompt you are testing. A judge that shares the system prompt shares its blind spots. Use a separate, strict rubric and a strong model.
- Requiring 100%. Model output varies between runs; a single flaky case will block every merge. Assert on a threshold and investigate the individual failures separately.
- Letting the set go stale. The inputs your users send change. A set from launch day does not know about the feature you shipped in March. Add cases from production every week.
- Comparing results across different models or settings. A pass rate only means something against a fixed configuration. When you change the model or the effort level, that is a change under test, not a new baseline.
Related reading
#quick question
Was this resource helpful?
by Danny