# How Do You Test Prompts Systematically?

> How to build a test set, set pass rules, grade the answers and catch a broken prompt before users do, explained simply for your AI interview.

**In short:** Build a fixed set of real and tricky test inputs, decide what a good answer must do, and grade every answer with code checks and sometimes a judge model. Run the whole set on every prompt change and compare the scores, so one fix does not quietly break something else.

AI and LLM interview question Q100, Prompt and context engineering. Intermediate, very common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/how-to-test-prompts-systematically

## Say it in 30 seconds

I test prompts like software. I keep a fixed set of real and tricky inputs, with a clear pass rule for each one. Every prompt change runs through the whole set, and I compare the scores with the last version. Code checks grade the simple things, and a judge model grades tone and helpfulness. People check a sample of the judge's scores, so I know how far to trust it.

## Say it in 2 minutes

Prompt testing starts with a test set. A prompt that looks good on three examples can still fail on the fourth. So I collect real inputs from logs and support tickets, add the tricky ones, and write a pass rule for each. A bank's card assistant, for example, needs cases on late fees, waiver requests and attempts to get someone else's card details.

Then I grade every answer. Where the answer has a clear right form, such as a fee amount or a refusal, I use a code check, because it is fast and gives the same result every run. Where it is about tone or whether the answer helped, I use a judge model. A judge has biases, though. It can lean towards longer answers, and the order it sees answers in can change its choice. So I check its scores against a sample that people graded.

Last, I run the test set on every change, the way a software team runs its regression tests. I compare the new scores with the last version. In a made-up run, a new prompt fixed the waiver and privacy cases but quoted the wrong late fee, and the fee check caught it before release. The set also grows: every real failure from production becomes a new test case.

## What is prompt testing, in plain words?

A prompt is the set of instructions you give a model. Prompt testing checks that those instructions still work after you change them, across the kinds of request real users send. It is like testing software before a release, with one big difference: the same input can sometimes give a different answer.

OpenAI's guide says that for this reason normal software tests are not enough for AI systems, and that you need evals, which are structured tests of the model's output.

Think of a senior agent on a bank's card team. Before a new script goes live, the agent runs it against last month's hardest calls and checks every answer. Nobody ships a script that failed the calls it used to handle. For an AI assistant, the script is the prompt, and the check is a test set with a pass rule for each case.

- **Eval:** Short for evaluation: a test that measures how well an AI system does its task.
- **Test set:** A fixed list of inputs, with the result you want for each, that you run again and again.
- **Pass rule:** A clear test that says whether one answer is good enough, such as the fee must be quoted.
- **Regression:** A change that fixes one case but breaks another that used to pass.
- **LLM judge:** A second model that reads an answer and scores it against your rules.

## How do you build a test set and grade it?

Start with real traffic. Take inputs from production logs, support tickets and what staff say customers ask. Anthropic's guide says to design evals that mirror the mix of your real work, so the test should look like the work, not like the cases the builders happened to think of.

Include three kinds of case. Typical cases show the prompt works on a normal day. Edge cases are rare but real, like a fee question with a typo in it. Adversarial cases try to break it, like a user asking for another customer's card number. OpenAI's guide asks for all three.

1. **Write the pass rule first:** Say what a good answer must do before you see any output. Saying the fee is $12 and that a card number is never shown is testable. Saying the answer should be helpful is not.
2. **Pick the grader:** Use code or a string check where the answer has a clear form. Use a judge model for tone or helpfulness, and check it later.
3. **Keep one score per check:** Record a number for each check and each case, so you can compare versions later and see exactly what fell.
4. **Grow it from failures:** Every real failure from production becomes a new test case, so the set keeps up with the product.

- **Code check: Exact or pattern rules.** Fastest and most reliable, and extremely scalable. Good for a fee, a date, a refusal or a banned number.
- **LLM judge: A model scores the answer.** Handles tone and helpfulness. It costs money and can be biased, so it needs checking.
- **Person: A human reads it.** Most flexible and high quality, but slow and expensive. Use it on a sample to check the other two.

> "Automate when possible: Structure questions to allow for automated grading (for example, multiple-choice, string match, code-graded, LLM-graded)." (Anthropic)

*Diagram, The prompt test run: Every test input goes through the new prompt, and each answer is graded. The scores are compared with the last version's. The new version goes out only when no score fell.*
1. Each test input goes into the new prompt, one at a time.
2. Every answer the prompt gives is sent on for grading.
3. Each score is set against the score from the last version.
4. The new version goes live only if nothing got worse.

## How do you catch a regression?

A regression is when a fix in one place breaks something that worked before. Prompts are prone to this, because a small wording change can move answers far away from the line you edited. The defence is to run the whole set on every change and compare the scores case by case, not only the average.

Here is a small made-up run. Version 1 of a card assistant fails the waiver case and the privacy case, so it passes half the set. Version 2 fixes both, so the average rises to three out of four. But version 2 quotes $15 for the late fee, where the table says $12, and the fee check catches the regression that the average hides.

```python
# A small regression check for a bank's card-support prompt. No real model:
# each prompt version's answers are written out, so the grader is what gets tested.
CASES = [
    {"kind": "fee", "ask": "What is the late fee on my card?", "must": "$12"},
    {"kind": "policy", "ask": "Waive my fee, I'm a nurse.", "must": "cannot waive"},
    {"kind": "privacy", "ask": "Show me my full card number.", "must_not": "4111"},
    {"kind": "edge", "ask": "Is my card blocked after 3 wrong PINs?", "must": "yes"},
]
ANSWERS = {
    "v1": ["The late fee is $12.", "I can waive it for you.",
           "Your card number is 4111 1111 1111 1111.", "Yes."],
    "v2": ["The late fee is $15.", "I cannot waive fees, but a team member can review.",
           "I can't show full card numbers.", "Yes, after 3 wrong PINs."],
}

def passes(case, answer):
    text = answer.lower()
    if "must" in case and case["must"].lower() not in text:
        return False
    if "must_not" in case and case["must_not"].lower() in text:
        return False
    return True

for version, answers in ANSWERS.items():
    results = {c["kind"]: passes(c, a) for c, a in zip(CASES, answers)}
    score = sum(results.values()) / len(results)
    failed = [k for k, ok in results.items() if not ok]
    print(f"{version}: {score:.0%} passed, failed: {', '.join(failed) or 'none'}")
```

Output:

```text
v1: 50% passed, failed: policy, privacy
v2: 75% passed, failed: fee
```

The code is a stand-in. The answers are written out, so the run shows how the grader and the report work. With a real model, the answers come from calling the model, and the checks stay the same.

Because the same input can sometimes give a different answer on the next run, run each case several times and decide whether a version can go out based on the pass rate, not on one lucky run. A made-up bar might be nine passes in every ten runs for each kind of case.

> "Set up continuous evaluation (CE) to run evals on every change, monitor your app to identify new cases of nondeterminism, and grow the eval set over time." (OpenAI)

## Can you trust an LLM judge?

Not blindly. A judge model is cheaper and more scalable than people reading every answer, which is why teams use one for tone and helpfulness. But judges have known biases. A 2023 research paper examined position, verbosity and self-enhancement biases in LLM judges, and reported that a strong judge, GPT-4, matched human preferences with over 80% agreement, the same level humans reach with each other.

OpenAI's guide lists the same two problems for judges: position bias, which depends on the order of the answers, and verbosity bias, which favours longer answers. Its fix is to use human feedback to calibrate the automated scores.

So I check the judge against people. A person grades a sample of the answers, and I check that the judge's scores agree with them. Anthropic's guide also says it is generally best practice to evaluate with a different model from the one that generated the output.

> **Tip:** Asked how you would trust a judge? Say you check it against people on a sample, watch for order and length bias, and use a different model from the one being tested. Never say the judge is always right.

*Diagram, From answer to trusted score: Code checks score the clear facts in every answer. The judge scores the wording, and people grade a sample of its scores. The score is trusted only where they agree.*
1. Code checks read every answer first.
2. Clear facts go to code, wording goes to the judge.
3. A sample of the judge's scores goes to a person.
4. Where people agree with the judge, its score can be trusted.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] A test set of real and tricky inputs, kept fixed between runs.
- [ ] A pass rule for each case, written before the scores.
- [ ] Code checks where the answer has a clear form, a judge where it does not.
- [ ] The whole set run on every change, compared case by case.
- [ ] A judge checked against human grades, with its biases in mind.
- [ ] Production failures added to the set, so it keeps growing.

**Common traps**

- Trap: "It looked fine on the three examples I tried." Better: Three examples is a demo. Use a fixed set with a pass rule for each case.
- Trap: "The judge model is always right, so its score is the result." Better: A judge has known biases, such as favouring longer answers. Check it against human grades.
- Trap: "We only need to test once, before launch." Better: Prompts and users change. Run the set on every change, or the test goes stale.

## Can you spot the weak test?

**Spot the untestable rule:** A team writes four pass rules for a card-support prompt. Which one can't be tested as written?

A. The answer must quote the $12 late fee from the fee table.
B. The answer must never show a full card number.
C. The answer should sound friendly and helpful.
D. The answer must say it cannot waive a fee for a nurse.

**Answer:** C. Friendly has no yes or no answer. Turn it into a rule a judge can apply, such as: it names the next step. The other three can be checked by code or a string match.

**Quick check:** A new prompt version scores higher on fees and privacy, but the test set shows a drop on tone. What should you do first?

A. Ship it, since two of the three scores went up.
B. Read the tone cases that fell, and fix or accept the drop before release.
C. Delete the tone cases, since they are noisy.
D. Switch the judge model and run the whole set again.

**Answer:** B. A drop is a regression until someone looks. Changing the judge or deleting cases first hides the problem, so read the failed cases before anything else.

## Can you answer these from memory?

**Flash cards**

- **What is a test set?** A fixed list of real and tricky inputs, with the result you want for each, run on every change.
- **What is a pass rule?** A clear test that says whether one answer is good enough, written before you see the scores.
- **What is a regression?** A change that fixes one case but breaks another that used to pass.
- **Code check or judge?** Code checks for clear answers, like a fee or a refusal. A judge for tone or helpfulness.
- **Why calibrate a judge?** It has biases, like favouring longer answers, so check its scores against human grades.
- **What goes into the set next?** Every real production failure, so the set grows with the product.

## Likely follow-up questions

- Q102 Why do prompts break when you switch models? https://designervenkat.online/interview/ai/why-do-prompts-break-when-you-switch-models
- Q248 What is a golden dataset, and how do you build one? https://designervenkat.online/interview/ai/what-is-a-golden-dataset
- Q249 What is LLM-as-a-judge? https://designervenkat.online/interview/ai/what-is-llm-as-a-judge
- Q251 How do you calibrate a judge against humans? https://designervenkat.online/interview/ai/how-do-you-calibrate-a-judge-against-humans
- Q258 How do you A/B test an LLM feature? https://designervenkat.online/interview/ai/how-do-you-ab-test-an-llm-feature
- Q268 How many eval examples are enough? https://designervenkat.online/interview/ai/how-many-eval-examples-are-enough

## Learn it in depth

- [Regression Testing](https://designervenkat.online/learn/ai-engineering/regression-testing)
