Sub topic 5
Writing Requirements You Can Test
Start with a measurable behavior
Assume you already understand basic product requirements, user stories, and the general role of a language model. You should also be comfortable reading short Python and JSON snippets.
An AI requirement should describe the behavior you need across a population of inputs. It usually cannot require one exact response because the model may phrase a correct answer in several ways. Instead, define:
- The population of inputs, such as questions in the
refund_policycategory. - The quality dimension, such as groundedness, which means that claims are supported by approved source material.
- The measurement method, such as a code check, human review, or model-based grader.
- The threshold, such as at least 95% of cases passing.
- Any separate rule for critical failures.
A useful requirement answers the question, “How will we decide whether this behavior is acceptable?”
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. This is a critical failure with a tolerance of 0 cases.The first sentence defines the population, quality dimension, measurement method, and threshold. The second sentence protects against an especially harmful error. A high overall pass rate cannot hide one dangerous contradiction.
Connect requirements to observable evidence
A requirement is testable when another person can apply its measurement method and reach a similar result. Avoid words such as “helpful,” “natural,” or “good” unless you define how to measure them.
| Vague statement | Testable replacement |
|---|---|
| Answers should be helpful. | At least 90% of typical support cases must resolve the stated issue or identify the next required action, according to the task-completion grader. |
| The assistant should be accurate. | For policy questions in the evaluation set, at least 95% of answers must contain no unsupported policy claim. |
| Responses should be concise. | At least 90% of answers must contain no more than 150 words, excluding quoted policy text. |
Separate quality dimensions when they can fail independently. An answer can be grounded but fail to answer the question. It can be concise but omit an important warning. Separate requirements make these differences visible.
Make the requirement specific without overfitting
Include representative input categories, but do not define success only through exact phrases. Phrase checks are useful for simple obligations, such as requiring the answer to mention that an item is damaged. They are weak for meaning, because a correct answer can use different wording.
A requirement should also state what happens when there are too few cases. For example, “at least 95%” is difficult to interpret with 10 cases. Set a minimum evaluation-set size or report a confidence interval for important decisions.
A small requirement record can make omissions visible:
requirement = {
"id": "REQ-3",
"population": "refund_policy questions",
"dimension": "groundedness",
"method": "groundedness grader",
"threshold": 0.95,
"critical_rule": "zero contradictions of refund amount or deadline",
}
required = {"id", "population", "dimension", "method", "threshold"}
missing = required - requirement.keys()
if missing:
raise ValueError(f"Missing fields: {sorted(missing)}")
print(f"{requirement['id']} is ready for evaluation.")This check does not prove that the feature is good. It checks that the requirement has the information needed to plan an evaluation.
Trace failures back to requirements
Requirements should connect the user problem to a measurable decision. A typical flow is:
Common errors include combining several dimensions into one score, omitting the input population, and setting a threshold without naming the grader. Another error is treating every failure equally. Missing a polite closing is different from inventing a refund deadline, so the requirement should reflect that difference.
Exercise
Rewrite this requirement so it can be tested: "The support assistant should give accurate and useful refund answers."
Show answer
For refund-policy questions in the evaluation set, at least 95% of answers must contain no claim that conflicts with the retrieved policy, as judged by the groundedness grader. At least 90% must answer the customer's stated question or identify the next required action. Any invented refund amount or deadline is a critical failure with zero tolerance.