Sub topic 5
Writing Requirements You Can Test
This chapter assumes you have written user stories or product requirements before, know roughly what a large language model does, and can read short Python and JSON snippets. It also assumes you have already picked quality dimensions and listed failure modes for your feature, as covered in the previous two chapters. Here you turn those two lists into statements that a test can pass or fail.
Why "the answer should be helpful" fails
A requirement is testable when two people who run the same evaluation reach the same verdict. "The assistant gives helpful refund answers" fails that test. One reviewer reads a polite, vague reply as helpful. Another reads it as a miss.
AI output varies from run to run, so a single expected output is the wrong target. A testable requirement describes a share of cases, a measurement, and a threshold. It also names the failures that no threshold may excuse.
The five parts of a testable requirement
Each requirement should answer five questions.
| Part | Question it answers | Example |
|---|---|---|
| Population | Which inputs does this apply to? | Questions in the "refund policy" category of the evaluation set |
| Dimension | Which quality property is measured? | Groundedness |
| Method | Who or what judges each output? | The groundedness grader |
| Threshold | How much must pass? | At least 95% |
| Critical rule | What may never happen? | No contradicted refund amount or deadline, tolerance 0 cases |
If any part is missing, the requirement leaves a decision to whoever runs the evaluation. That person then makes the call on the day you most want it made consistently.
A worked example
This requirement comes from a support assistant that answers questions about refunds.
REQ-3 Groundedness
For questions in the "refund policy" category of the evaluation set, at least 95% of answers must make only claims supported by the retrieved policy text, as judged by the groundedness grader.
No answer may state a refund amount or deadline that contradicts the policy (severity: critical, tolerance: 0 cases).Read it against the five parts:
- Population: "questions in the 'refund policy' category of the evaluation set". It points to a dataset you can open, not to "refund questions in general".
- Dimension: groundedness, meaning claims are supported by the retrieved text.
- Method: "the groundedness grader". The requirement does not describe how the grader works. It must name a grader that exists and is documented elsewhere, such as a code check, a human rubric, or a model judge.
- Threshold: 95%. This number is a product decision, and you should be able to defend it. The chapter on acceptance criteria covers how to choose it.
- Critical rule: the second paragraph. It uses a different kind of limit, explained next.
Rate requirements and zero-tolerance rules
The two paragraphs of REQ-3 do different jobs, and you should not merge them.
A rate requirement accepts some failures. At 95%, a small share of answers may include an unsupported claim. This fits quality dimensions where small slips are tolerable, such as tone, completeness, and minor wording problems.
A zero-tolerance rule accepts none. It attaches to a failure mode you ranked as critical, such as stating a wrong refund deadline or leaking another customer's data. If you folded this into the 95% rate, a system could ship while giving wrong refund amounts in 4% of cases. The rate would still be met.
Two points about zero-tolerance rules in practice:
- "0 cases" applies to your evaluation set, not to the real world. A clean run of 50 cases does not prove the failure rate is zero. As a rough guide (the "rule of three"), 0 failures in n independent cases is consistent with a true failure rate up to about 3/n. For n = 50 that is about 6%. A zero-tolerance rule therefore needs enough cases, including adversarial ones, to be meaningful. It also needs monitoring after launch.
- Write the severity and the tolerance in the requirement, as REQ-3 does. A reader should not have to guess which failures block a release.
Wording that makes requirements untestable
Most bad requirements fail in the same few ways. The table shows each pattern with a rewrite.
| Weak wording | Problem | Testable rewrite |
|---|---|---|
| The assistant should be accurate. | No population, method, or threshold | For questions in the "refund policy" category, at least 95% of answers make only claims supported by the retrieved policy text, per the groundedness grader. |
| Responses should be fast. | No percentile or condition | 95th percentile time to first token is under 2 seconds for inputs up to 500 words. |
| The assistant must never hallucinate. | Cannot be proven, and "hallucinate" is undefined | No answer may state a refund amount or deadline that contradicts the policy (0 cases in the critical subset). |
| Tone should be friendly. | No judge or rubric | At least 90% of answers score 4 or higher on the 5-point tone rubric, as rated by two human reviewers. |
| Handle edge cases well. | Edge cases are not listed | For the 30 edge cases tagged "refund_edge", at least 90% either answer correctly or hand off to a human agent. |
Three habits fix most of these:
- Replace adjectives with a measurement. "Accurate", "good", and "safe" each need a grader and a pass condition.
- Replace "always" and "never" with a rate, or with a named critical failure and a tolerance.
- Name the dataset or subset the requirement runs against, so the population is not whatever the tester picks.
Keeping requirements as data
Requirements that live only in a document drift away from the tests. Keeping them as data lets the evaluation report which requirement each result belongs to. The sketch below stores a rate requirement and checks it against graded results. It only reads results, so it works with any grader.
from dataclasses import dataclass
@dataclass
class Requirement:
id: str
category: str
min_rate: float
min_cases: int = 20
def check_rate(req, results):
in_scope = [r for r in results if r["category"] == req.category]
if len(in_scope) < req.min_cases:
return {"id": req.id, "status": "insufficient_data", "cases": len(in_scope)}
rate = sum(r["passed"] for r in in_scope) / len(in_scope)
status = "met" if rate >= req.min_rate else "not_met"
return {"id": req.id, "status": status, "rate": round(rate, 3), "cases": len(in_scope)}
req3 = Requirement(id="REQ-3", category="refund_policy", min_rate=0.95)
results = [{"category": "refund_policy", "passed": i != 7} for i in range(40)]
print(check_rate(req3, results))This run prints {'id': 'REQ-3', 'status': 'met', 'rate': 0.975, 'cases': 40}. One failure in 40 cases is 97.5%, which clears the 95% threshold. The insufficient_data status is deliberate. A requirement with too few cases should not report "met" by default.
Tracing requirements to evaluation cases
Each evaluation case should point back to the requirement it supports, through its category and its severity. The next chapter builds the dataset in detail. This is the shape of one case:
{"id": "refund-014", "category": "refund_policy", "type": "edge_case", "input": "I bought this 45 days ago and it arrived damaged. Can I still return it?", "must_include": ["damaged"], "must_not_include": ["guaranteed refund"], "severity_if_failed": "critical"}The category value is the "refund policy" population in REQ-3. The severity_if_failed value marks the case as part of the zero-tolerance rule. If the policy does not promise a refund after 45 days, the must_not_include phrase turns one concrete wrong behavior into an automatic check.
Tracing runs in both directions, and you should check both:
- Every requirement has at least one case, ideally dozens. A requirement with no cases is untested.
- Every case supports some requirement. A case that supports nothing is either unneeded or a sign that a requirement is missing.
Common errors
- Hiding the grader. "Judged by the groundedness grader" is only meaningful if that grader is defined. A model judge with an undefined rubric makes the requirement as vague as the one it replaced.
- Picking a threshold with no basis. 95% looks tidy but may be too strict for a draft feature or too lax for a medical one. Tie it to user impact and to a measured baseline.
- Mixing dimensions in one requirement. "Answers must be grounded, polite, and under 100 words" cannot report which part failed. Write one requirement per dimension.
- Testing only typical inputs. If the population is "the evaluation set", the set must include the edge and adversarial cases that your failure-mode list predicts.
- Treating the requirement as final. Observed failures in production will expose cases the first draft missed. Revise the requirement and add the case, and record the change.
Check your understanding
Exercise
A team writes this requirement for a meeting-summary feature: "Summaries must be accurate and should never invent action items." Rewrite it as two testable requirements. One is a rate requirement and one is a zero-tolerance rule. Name the population, grader, threshold, and tolerance in each.
Show answer
One valid answer. REQ-A (rate, dimension: coverage and accuracy): For transcripts in the "standard meeting" category of the evaluation set, at least 90% of summaries include every decision recorded in the reference notes and make no claim that contradicts the transcript, as judged by a human reviewer using the 3-point summary rubric. REQ-B (zero tolerance, severity: critical): For all transcripts in the evaluation set, no summary may list an action item or owner that does not appear in the transcript, as checked by a code check that compares each listed action item against the transcript text and flagged for human review when it finds no match. Tolerance: 0 cases. Both name a population, a grader, and a pass condition. Only REQ-A has a rate threshold, while REQ-B is a tolerance of 0 cases. Splitting them stops a high average from hiding invented action items. A strong answer also notes that REQ-B needs enough cases, including transcripts with no action items, to make "0 cases" meaningful.
Exercise
Your requirement says "at least 95% of answers must pass", and your evaluation set has 20 cases in that category. Your system fails 2 of them. Does the requirement pass? What should you do about the set size?
Show answer
It does not pass. 18 of 20 is 90%, which is below 95%. With 20 cases, one failure is the most the threshold allows, so the result is very sensitive to a single case. Add more cases to the category, or set a minimum case count in the requirement, so one or two results cannot swing the verdict. Until the set is larger, treat the result as indicative, not conclusive.