---
title: "How do I test and evaluate prompts so changes do not break things?"
description: "Treat a prompt like code: keep a set of real inputs with expected outputs, score them automatically on every change and track the pass rate over time."
url: https://www.danny.engineering/answer/ai/how-do-i-test-and-evaluate-prompts-so-changes-do-not-break-things
author: Danny
published: 2026-12-03T00:00:00.000Z
updated: 2026-12-03T15:35:00.000Z
tags: ["AI"]
---

# How do I test and evaluate prompts so changes do not break things?

## 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.


```json
[
  { "id": "refund-1", "input": "I want my money back, the app crashed twice", "expected": { "category": "refund" } },
  { "id": "bug-3", "input": "Login button does nothing on Safari", "expected": { "category": "bug" } },
  { "id": "other-2", "input": "Do you have a careers page?", "expected": { "category": "other" } }
]
```


## 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.


```typescript
const result = await classify(testCase.input);
expect(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.


```typescript
const Verdict = z.object({ pass: z.boolean(), reason: z.string() });

async function judge(input: string, output: string, rubric: string) {
  const res = await client.messages.parse({
    model: 'claude-opus-5-5',
    max_tokens: 512,
    system: 'You grade answers against a rubric. Be strict: pass only if every point is met.',
    messages: [{ role: 'user', content: `Rubric:\n${rubric}\n\nQuestion:\n${input}\n\nAnswer:\n${output}` }],
    output_config: { format: zodOutputFormat(Verdict) },
  });
  return res.parsed_output;
}
```


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.


```typescript
import { describe, it, expect } from 'vitest';
import cases from './cases.json';
import { classify } from '../src/classify';

const limit = Number(process.env.EVAL_LIMIT ?? cases.length);
const results: boolean[] = [];

describe('ticket classifier', () => {
  it.each(cases.slice(0, limit))('$id', async (c) => {
    const out = await classify(c.input);
    results.push(out.category === c.expected.category);
  });

  it('passes at least 90% of cases', () => {
    const rate = results.filter(Boolean).length / results.length;
    expect(rate).toBeGreaterThanOrEqual(0.9);
  });
});
```


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.


```typescript
// src/prompts/classify.ts
export const CLASSIFY_SYSTEM = `You sort incoming support tickets into exactly one category.
Categories: refund, bug, feature_request, other.
Choose "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

- [Define your success criteria](https://platform.claude.com/docs/en/test-and-evaluate/define-success)
- [Developing test cases](https://platform.claude.com/docs/en/test-and-evaluate/develop-tests)
- [Structured outputs](https://platform.claude.com/docs/en/build-with-claude/structured-outputs)
- [Vitest guide](https://vitest.dev/guide/)
