What makes these features different to test
Three things. The output is non-deterministic, so a single run is a sample, not a result. The specification is partly the prompt, so a one-word change to the instructions is a code change that can alter behaviour anywhere. And quality has several dimensions (correct, complete, grounded, safe, in the right tone) that a single assertion cannot capture. The response is not to give up on assertions but to layer them, cheapest and most reliable first, as the automation pyramid layers tests by cost.
The method
Write the behaviour specification
List what the feature must always do, must never do, and should do well. Must-always and must-never items become assertions; should-do-well items become rubric criteria.
Build deterministic checks
Parse the output. Assert on format, schema, length limits, required fields, language, and forbidden strings or patterns. These run on every commit and never flake.
Add property checks
Check relations that need no expected value: every figure in a summary appears in the source, every citation points to a retrieved passage, the answer does not change when irrelevant context is reordered.
Define the rubric
For quality, write a scoring rubric with three to five criteria and anchored levels, and have reviewers apply it to a sample. Calibrate any model grader against those human scores before trusting it.
Run for rates
Run each case three to five times at production settings. Pass criteria are rates: at least 98 percent of runs pass all deterministic checks, the mean rubric score on the suite stays at or above the baseline.
Freeze a regression suite
Version 200 to 500 cases covering every slice and every past defect, and run it on each prompt, model, retrieval or tool change, comparing against the last accepted run.
Test the attack surface
Add adversarial cases for prompt injection through user input and retrieved documents, data leakage, excessive tool permissions and unsafe requests, using the OWASP list as a checklist.
Model graders need testing too
Using one model to grade another is fast and, with care, useful. Zheng and colleagues found that strong model graders agreed with human preferences about as often as humans agreed with each other, and also documented position bias (preferring the first answer shown), verbosity bias (preferring longer answers) and self-preference. So test the grader like any other instrument: score at least 100 cases with both humans and the grader, report agreement, swap answer order to measure position bias, and re-check agreement whenever the grader's prompt or model changes. The approach mirrors the detector benchmark protocol: an instrument is trusted to the extent its error rate has been measured.
| Check type | Example | Determinism | When it runs |
|---|---|---|---|
| Deterministic | Output parses as the schema; under 120 words; no personal data patterns | Exact | Every commit |
| Property | All numbers in the answer appear in the source passage | Exact per run, rate across runs | Every commit |
| Rubric, human | Correctness, completeness, tone on a 1 to 4 scale | Agreement measured | Before release, on a sample |
| Rubric, model grader | Same rubric applied by a grader model | Calibrated against humans | Every prompt or model change |
| Adversarial | Injected instruction inside a retrieved document is ignored | Rate across runs | Every change, and in the release gate |
Prompts are code
Keep prompts in the repository, reviewed and versioned like source, and run the regression suite on every change. A prompt edit that fixes one complaint routinely breaks three other cases, and the suite is the only way to see it. Record the model version and settings with every run, because a supplier's silent update is a change the team did not make but must still test. The continuous testing guide covers the gates; treat a drop in the regression pass rate like a failing build.
No prompt change ships without a regression run compared against the last accepted baseline, and the diff of failing cases attached to the review.
Exploratory sessions still find what the suite cannot
Scripted evaluation measures the behaviour you anticipated. Exploratory testing finds the rest: charter a session on a risk (for example, users pasting long documents in another language) and let a tester probe for 60 to 90 minutes, then turn every finding into a regression case. For the evaluation data behind the suite, follow the test set design guide, and for the wider approach see how to test AI systems.
Common questions
How do you write assertions for non-deterministic output?
Assert on what must hold for any acceptable output: format, schema, length, required content, forbidden content, and relations to the input. Run each case several times and pass on the rate of runs that satisfy every assertion.
Can a language model grade another model's output?
Yes, once it has been calibrated. Measure its agreement with human reviewers on at least 100 cases, check for position and length bias, and re-calibrate whenever the grader changes. Treat it as an instrument with a known error rate.
How large should a regression suite for an LLM feature be?
Typically 200 to 500 cases: enough to cover every slice and every past defect, small enough to run on each prompt or model change. Keep the larger evaluation set for release decisions.
What counts as a change that needs re-testing?
Any change to the prompt, the model or its version, generation settings, the retrieval index or its chunking, the tools the model can call, and the preprocessing of inputs. Each can change behaviour on cases nobody touched.
How do you test for prompt injection?
Include cases where user input or retrieved content contains instructions that conflict with the system's rules, and assert that the feature ignores them, does not reveal hidden instructions, and does not call tools it should not. Run them on every change.
Sources
- OWASP Top 10 for Large Language Model Applications
- Ribeiro et al., Beyond Accuracy: Behavioral Testing of NLP Models with CheckList (2020)
- NIST AI 600-1, Generative Artificial Intelligence Profile of the AI RMF
Further reading named in the text
- Lianmin Zheng, Wei-Lin Chiang, Ying Sheng and colleagues, Judging LLM-as-a-Judge with MT-Bench and Chatbot Arena (NeurIPS Datasets and Benchmarks, 2023)
- Percy Liang, Rishi Bommasani, Tony Lee and colleagues, Holistic Evaluation of Language Models (Transactions on Machine Learning Research, 2023)
- ISTQB, Certified Tester AI Testing (CT-AI) syllabus, version 1.0 (2021)
- James Bach, Session-Based Test Management (Software Testing and Quality Engineering magazine, 2000)
This guide is part of the testing AI systems hub. It is best read alongside how to test ai systems and QA of AI-generated test cases and code, which cover the neighbouring questions.