Sub topic 2
Why AI features need different requirements
This chapter assumes you can read a user story or acceptance criterion, you know roughly what a large language model does (text in, generated text out), and you can follow short Python snippets. It explains why the requirements habits you use for ordinary software break down for AI features. It also introduces the vocabulary later chapters use to fix that.
A requirement that works for normal software
Take a conventional feature: "When a customer enters a valid discount code, the order total is reduced by the code's percentage."
You can write this as a test with one input and one exact expected output. Enter SAVE10 on a $100 cart and the total must be $90.00. The test passes or fails. Run it a thousand times and you get the same answer a thousand times. If it fails once, something changed: the code, the data, or the environment. Failure is a signal that a defect exists.
Requirements for deterministic software lean on three assumptions:
- The same input produces the same output.
- A single correct output exists, or a small set of them.
- One passing test is good evidence the behavior holds.
AI features break all three.
Where the variation comes from
Consider an AI feature that answers customer questions about refunds. Several things make its output vary.
- Sampling. Most language models pick each next word from a probability distribution. A setting called temperature controls how much randomness is allowed. Even at low temperature, outputs can differ between calls, because of hardware differences, batching, and provider-side changes.
- Input phrasing. "Can I return this?" and "I want my money back for this" mean nearly the same thing to a person. The model may handle them differently.
- Context. If the feature retrieves policy documents before answering, a different retrieved passage can change the answer.
- Model updates. A provider may update the model behind the same name, or you may switch versions. Your code is unchanged but behavior shifts.
- Open-ended correctness. Many valid answers exist. "You can return it within 30 days" and "Our policy allows returns for up to a month" are both fine, and neither matches the other as a string.
So for an AI feature, "the feature works" is not a property of one run. It is a property of the whole population of inputs and outputs the feature will produce.
Requirements describe distributions
A requirement for an AI feature has to say how often the behavior must hold, across which inputs, and how you will measure it. Compare:
| Aspect | Deterministic requirement | AI feature requirement |
|---|---|---|
| Statement | "The total is reduced by the code's percentage." | "At least 95% of refund-policy answers make only claims supported by the retrieved policy text." |
| Input | One example | A population of inputs, described by categories |
| Expected output | One exact value | A property that many different outputs can satisfy |
| Evidence | One passing test | A pass rate over many cases |
| Failure | A defect to fix | Some failures expected, with a tolerance by severity |
| Check | Equality assertion | Code check, human review, or model-based judge |
The second column is not a weaker standard. It is a more honest one. A claim like "the assistant never gives wrong refund information" cannot be verified for a nondeterministic system, and a requirement you cannot verify cannot guide a release decision.
What a testable AI requirement contains
The example requirement from this tutorial's plan shows the parts:
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).It has five parts:
- Population of inputs. Questions in the "refund policy" category of the evaluation set. Without this, "95%" has no denominator.
- Quality dimension. Groundedness, meaning claims are supported by the source text. Later chapters cover how to choose dimensions.
- Measurement method. The groundedness grader. Someone else can run it and reach the same number.
- Threshold. At least 95%.
- Zero-tolerance rule. A separate line for a critical failure, because an average hides rare but serious errors. A 96% pass rate is compatible with the 4% failures all being wrong refund amounts.
Keep the zero-tolerance rule separate from the percentage. Averages answer "how good is it typically?" Severity rules answer "what must never happen?"
Seeing the variation in numbers
Running a case once tells you very little. The following script simulates a feature that gives the correct 30-day answer about 90% of the time, then estimates the pass rate from small and large samples. The fake_generate function is a stand-in for a real model call.
import math
import random
def fake_generate(question, rng):
# Stand-in for a model call: correct about 90% of the time.
if rng.random() < 0.9:
return "You can return it within 30 days of delivery."
return "Returns are accepted for up to 60 days."
def passes(output):
return "30 days" in output
def wilson_interval(passed, n, z=1.96):
# 95% confidence interval for a pass rate.
p = passed / n
denom = 1 + z * z / n
centre = (p + z * z / (2 * n)) / denom
half = z * math.sqrt(p * (1 - p) / n + z * z / (4 * n * n)) / denom
return centre - half, centre + half
rng = random.Random(7)
question = "How long do I have to return an item?"
for n in (5, 20, 200):
passed = sum(passes(fake_generate(question, rng)) for _ in range(n))
low, high = wilson_interval(passed, n)
print(f"n={n:>3} passed={passed:>3} rate={passed / n:.2f} 95% interval=({low:.2f}, {high:.2f})")The exact counts depend on the random seed, but the pattern does not. With 5 runs, the interval spans a huge range, so even a perfect 5 of 5 cannot show the true rate is above 95%. With 200 runs, the interval narrows to a few points on each side of the observed rate. The takeaway for requirements is that a threshold is only meaningful alongside a sample size large enough to tell whether you met it.
Putting it together in a workflow
The change in thinking shows up in how you move from idea to release decision.
Note that the AI path has a loop. Because you cannot reason your way to a guarantee, you measure, adjust, and measure again. That is why the evaluation (the dataset, graders, and metrics covered in later chapters) is part of the requirement and not an afterthought.
Common mistakes
Writing a requirement as a single example. "When asked about returns, the assistant says 30 days" describes one output for one phrasing. It will pass on the example and say nothing about the other thousand ways users ask.
Using vague quality words. "Answers should be accurate and helpful" has no population, method, or threshold. Two reviewers will disagree about whether it is met.
Asking for 100%. For most dimensions a 100% threshold across a sampled population is either unachievable or untestable. Reserve zero tolerance for specific, severe, well-defined failures, like a wrong refund amount, and use rates for the rest.
Treating one good demo as evidence. A demo is a sample of one, chosen by a person who wants it to work. Run the feature over a representative set instead.
Testing exact string matches. Comparing the output to a reference string will fail valid paraphrases and teach you to ignore failures. Check properties of the output (it includes the deadline, it does not promise a guaranteed refund) or use a grader built for the dimension.
Ignoring the sample size. A pass rate of 19 out of 20 and a threshold of 95% look like a match, but as the script above shows, 20 cases cannot distinguish a 95% feature from an 80% one.
What this changes in practice
Four habits follow from this chapter, and the rest of the tutorial builds on them.
- Define the population before the threshold. You need to know what the percentage is a percentage of.
- Name the measurement method in the requirement itself, so the number can be reproduced.
- Pair every rate with a severity rule for failures that cannot be averaged away.
- Treat sample size as part of the requirement. A threshold you cannot verify with the cases you have is not yet a usable requirement.
Next, you will choose the quality dimensions that matter for your feature, since each requirement targets one dimension, such as groundedness, correctness, tone, or safety.
Exercise
A teammate writes this requirement for a support chatbot: "The assistant must always give the correct return deadline." Rewrite it as a testable AI requirement, and say which two parts of the original make it untestable.
Show answer
The original is untestable because "always" implies 100% across all possible inputs, which cannot be verified for nondeterministic output, and because it names no input population, measurement method, or threshold. A testable version: "For questions in the 'return deadline' category of the evaluation set (at least 100 cases covering varied phrasings), at least 97% of answers must state the deadline stated in the policy, as judged by a code check for the correct number of days. Any answer that states a deadline contradicting the policy is a critical failure (tolerance: 0 cases)." It includes a population, a dimension (correctness of the deadline), a method, a threshold, and a separate zero-tolerance rule.
Exercise
You run your feature on 10 evaluation cases and 10 pass. Your requirement is a pass rate of at least 95%. Can you conclude the requirement is met? Explain in two or three sentences.
Show answer
No. With only 10 cases, a perfect score is still consistent with a true pass rate well below 95%. The confidence interval for 10 of 10 reaches down to roughly 72%. You need a larger sample, often a hundred or more cases for a 95% threshold, before the observed rate can show the threshold is met.