Skip to content
Figure 1Where each check runs for an LLM feature: fast deterministic checks on every commit, rubric evaluation before release
Where each check runs for an LLM feature: fast deterministic checks on every commit, rubric evaluation before releaseCommitunitlintstatic analysis< 5 minBuildcomponentcontract< 10 minDeploy to testAPIintegrationsecurity scan< 20 minAcceptanceend-to-end smokeexploratory< 30 minProductionsynthetic checkscanarycontinuous
The same pipeline shape as any service. Deterministic and property checks are cheap and run on every change; rubric grading and the full evaluation set run on prompt or model changes and before release.

Test design for LLM features: assertions, rubrics and regression

A feature built on a large language model is a piece of software whose central function is written in natural language and executed by a component nobody on the team can read. The prompt changes weekly, the model underneath changes when the supplier updates it, and the output is different every run. Test design for these features borrows from every part of the discipline: property checks from automation, rubrics from exploratory testing, and statistics from performance work.

Quick answer

Layer the assertions: deterministic checks first (format, length, required fields, forbidden content), then property checks (the answer cites only facts in the source), then rubric scores from reviewers or a calibrated model grader. Run each case several times and pass on rates, not single outputs. Keep a versioned regression suite that runs on every prompt, model or retrieval change.

Key figures

Assertion layers
3: deterministic, property, rubric
Runs per case
3 to 5 for pass-rate checks
Regression suite
200 to 500 cases, versioned
Grader calibration
agreement with humans on 100+ cases
Re-run trigger
prompt, model, retrieval or tool change
Security list
OWASP LLM Top 10

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

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

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

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

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

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

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

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

Assertion layers for an LLM feature, cheapest and most reliable first
Check typeExampleDeterminismWhen it runs
DeterministicOutput parses as the schema; under 120 words; no personal data patternsExactEvery commit
PropertyAll numbers in the answer appear in the source passageExact per run, rate across runsEvery commit
Rubric, humanCorrectness, completeness, tone on a 1 to 4 scaleAgreement measuredBefore release, on a sample
Rubric, model graderSame rubric applied by a grader modelCalibrated against humansEvery prompt or model change
AdversarialInjected instruction inside a retrieved document is ignoredRate across runsEvery 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.

Test lead's rule

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

  1. OWASP Top 10 for Large Language Model Applications
  2. Ribeiro et al., Beyond Accuracy: Behavioral Testing of NLP Models with CheckList (2020)
  3. 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.