The Short Answer
How do you test an AI feature?
Build a set of real example inputs with the answer or behaviour you expect, run the feature against all of them, and score the results with a mix of automatic checks, model-based grading and human review. Re-run the whole set before every change to prompts, models or data, and keep monitoring real usage after launch.
Without this, every change is judged by trying a few questions and deciding it feels better. That is how teams ship an improvement for one case and a regression for ten others.
Read the transcript
A team changes one sentence in an AI prompt. They try five questions. It feels better. They ship it. Ten other answers just got worse. AI features can’t be tested like normal code. The same input can give a different answer, and wrong answers sound confident. So how do you test one properly? Five steps. Collect real examples. Write down the answer you expect. Score every run. Re-run the whole set before each change. And keep watching after launch. Score with a mix of methods. Rules where there is one right answer. A second model to grade at scale. And people, to check the grader is right. You can start with fifty real examples, and add every failure you find. If you can’t measure it, you can’t safely change it. The full guide is free at loomstrat.com.
Why AI Needs a Different Approach
- Outputs vary. The same question can produce different wording, and sometimes a different answer.
- Correctness is often a judgement. A summary can be accurate but miss the point. There is rarely a single right string to compare against.
- Small changes ripple. Editing one sentence in a prompt or moving to a new model version can change behaviour on unrelated inputs.
- Failures are plausible. Wrong answers are fluent and confident, so casual checks miss them.
Ordinary software testing still applies to everything around the model. Evaluation is the extra layer for the model’s behaviour.
Step 1: Build a Test Set
- 1
Collect real inputs
Use real questions, documents or requests from users or support logs, not ones the team invented.
- 2
Cover the spread
Include common cases, hard cases, edge cases and inputs the feature should refuse.
- 3
Write the expected result
An exact answer where one exists; otherwise the facts the answer must contain and must not contain.
- 4
Start small
Fifty well-chosen examples are enough to begin. Grow the set every time a real failure is found.
- 5
Keep it fixed
Version the test set so scores from different weeks are comparable.
Step 2: Decide How to Score
| Method | How it works | Good for |
|---|---|---|
| Exact or rule-based checks | Compare against a known value or check format, length, required fields | Classification, extraction, structured output |
| Reference comparison | Check the answer contains the required facts and none of the forbidden ones | Question answering |
| Model-graded | A second model scores each answer against written criteria | Tone, helpfulness, faithfulness to sources, at scale |
| Human review | People rate a sample of answers | Calibrating the other methods; high-stakes features |
| Pairwise comparison | Reviewers or a model choose the better of two versions | Deciding between prompts or models |
Model-graded scoring is useful but must itself be checked. Have people grade a sample and confirm the grading model agrees with them before trusting it.
Step 3: Measure the Right Things
- Accuracy. Is the answer correct?
- Faithfulness. For retrieval features, is every claim supported by the passages provided?
- Retrieval quality. Did the search step find the right passages in the first place? Measure this separately; it is often the real problem.
- Refusals. Does the feature decline when it should, and only when it should?
- Safety. Does it resist prompt injection and attempts to extract data? The OWASP Top 10 for LLM applications is a good checklist.
- Cost and speed. Tokens used and response time per request.
Step 4: Run It on Every Change
Treat the evaluation like a test suite in a CI/CD pipeline. Run it automatically when prompts, model versions, retrieval settings or source data change. Compare scores with the last release and block the change if important measures drop.
Run each input more than once when outputs vary. A feature that answers correctly four times out of five is not the same as one that always does.
Step 5: Monitor After Launch
- Log inputs and outputs, with appropriate data protection controls.
- Capture feedback. Thumbs up and down, edits users make to drafts, and escalations to a person.
- Sample and review a small share of real conversations every week.
- Feed failures back into the test set so the same mistake is caught next time.
- Watch for drift. Provider model updates and changes to your content can shift behaviour without any change to your code.
Evaluation and Risk Management
For higher-risk uses, document what the feature is for, how it was tested, its known limits and who reviews it. The NIST AI Risk Management Framework provides a structure that maps well to this, and the records help with UK GDPR obligations; see UK GDPR and AI.
Frequently Asked Questions
How many test examples do I need?
Around fifty well-chosen real examples is a practical start. Add every real failure you find, and grow towards a few hundred for important features.
Can an AI grade another AI?
Yes, and it is useful at scale, but check its grades against human ratings on a sample first, and re-check when you change the grading prompt or model.
What is a regression in an AI feature?
A change that improves some answers but makes others worse. Running the full test set before each release catches it.
How do I test retrieval separately?
For each test question, record which passages should be found, then measure how often the search step returns them near the top.
Do I still need normal software tests?
Yes. Everything around the model, from permissions to integrations, still needs unit, integration and end-to-end tests.