Sub topic 11
Defining How You Will Measure Quality
Assume you understand basic software product development, have general awareness of machine learning and large language models, and can read short Python snippets. This chapter focuses on evaluation: deciding whether a feature works well enough to justify its risks and operating cost.
Start with a measurable outcome
“Use AI to improve support” is not a quality target. Convert the product goal into an observable outcome:
- User: Who receives the feature?
- Task: What decision or action does it support?
- Metric: What measurable result indicates success?
- Threshold: What minimum result is acceptable?
- Comparison: What existing approach must it beat?
For example, a support-ticket classifier might have this specification:
| Element | Example |
|---|---|
| User | Support operations team |
| Task | Route each ticket to a queue |
| Primary metric | Correct queue assignment |
| Threshold | At least 90% accuracy |
| Comparison | Existing keyword rules |
A metric is useful only when it reflects the product outcome. Accuracy can hide important failures when one category is much more common than another. For a safety-sensitive classifier, measure precision, recall, or the error rate for each important category.
Evaluate against a baseline
A baseline is a simple method used for comparison. It might be a rule, keyword search, manual process, or current user interface. Measure it on the same examples and with the same metric as the AI system.
def accuracy(predict, examples):
correct = sum(
1 for text, expected in examples
if predict(text) == expected
)
return correct / len(examples)
examples = [
("please refund my order", "billing"),
("the app crashes on launch", "bug"),
("my invoice amount is wrong", "billing"),
]
def keyword_baseline(text):
text = text.lower()
if "refund" in text or "invoice" in text:
return "billing"
return "bug"
print(f"Baseline accuracy: {accuracy(keyword_baseline, examples):.0%}")If the AI system does not improve the outcome enough to offset its latency, cost, and failure modes, the baseline is the better product decision.
Build a representative test set
A test set is a fixed collection of examples with trusted expected results. Keep it separate from examples used to tune prompts or train a model. Otherwise, the evaluation can look better without predicting real behavior.
Include:
- Common cases, which show normal performance.
- Rare but important cases, which expose dangerous failures.
- Ambiguous cases, where reasonable people may disagree.
- Different languages, customer types, devices, or input lengths.
- Adversarial or malformed inputs, when users can provide them.
Record how labels were created. For subjective outputs, use multiple reviewers and define a rubric. A rubric is a scoring guide that states what counts as correct, incomplete, unsafe, or irrelevant.
Combine offline and product measures
Offline evaluation uses a fixed test set before launch. It is repeatable and helps compare versions. Online evaluation measures behavior in real use after launch.
Useful online measures include:
- Task completion rate.
- User correction or rejection rate.
- Escalation to a human.
- Time saved.
- Retention or conversion, when appropriate.
- Cost per successful task.
- Latency at the relevant percentile, such as p95.
Do not replace quality with engagement alone. Users may click a poor recommendation because the interface makes it prominent.
Define the decision rule
Write the launch rule before reviewing results. For example: “Run a pilot only if AI accuracy is at least 5 percentage points above the baseline, no protected user group falls below 90%, and every high-risk output receives human review.”
This prevents changing the standard after seeing the results. Store the test set, metric definitions, threshold, model version, prompt version, and evaluation date so later changes remain comparable.
Exercise
An AI classifier has 94% overall accuracy, but only 78% accuracy for a small category involving account closure. The baseline has 91% overall accuracy and 90% for account closure. Should the AI system launch automatically?
Show answer
No. The overall score hides a high-impact slice where the AI is worse. Investigate the errors, improve or route that category to a safer fallback, and re-evaluate against the baseline.