Sub topic 5
Cover the input space with tagged slices
This chapter assumes you can read JSONL, write basic Python, and know what a proportion and a sample size are. It also assumes you have a test case schema with a tags field, as in the earlier chapter on schema design.
Why one overall score hides problems
An overall accuracy number averages every case together. If 90% of your cases are easy and common, a model can score 92% while failing nearly every rare or hard input. A slice is a named subset of cases that share a property, such as a topic, input length, or language. You mark each case with tags, then report a score for each slice.
Slices turn "the app works" into specific claims, such as "the app answers refund questions well but fails on non-English input."
Choose slice dimensions
Pick dimensions from how your app is used and where it is likely to fail. Common ones:
| Dimension | Example tags |
|---|---|
| Topic or intent | `returns`, `shipping`, `billing` |
| Input type | `short`, `long`, `multi_turn` |
| Difficulty | `easy`, `hard` |
| Language | `en`, `es` |
| Case kind | `common`, `edge`, `adversarial` |
The case kind matters most for coverage. Common cases reflect real traffic. Edge cases are valid but unusual inputs, such as an empty message or a very long one. Adversarial cases try to break the app, such as a prompt injection or a request that conflicts with policy.
Check coverage before you run anything
A case can carry several tags, so one case can count in more than one slice. Count how many cases each slice has before you trust any score.
import json
from collections import Counter
def slice_counts(path):
counts = Counter()
with open(path, encoding="utf-8") as f:
for line in f:
if line.strip():
case = json.loads(line)
counts.update(case["tags"])
return counts
def find_gaps(counts, required, minimum=20):
return {tag: counts.get(tag, 0) for tag in required
if counts.get(tag, 0) < minimum}Call find_gaps(slice_counts("cases.jsonl"), ["returns", "shipping", "edge", "adversarial"]). Any tag it returns is under-covered, and a score on it is weak evidence. The minimum of 20 is an example. Choose it with the confidence tools from the chapter on dataset size.
Common errors
- Copying production traffic as is. Traffic is dominated by common cases. Sample extra edge and adversarial cases on purpose, so rare slices are not empty.
- Tags that overlap in meaning. If
billingandpaymentsmean nearly the same thing, scores split across both and neither is reliable. Write down a one-line definition for each tag. - Too many dimensions. Crossing five dimensions creates hundreds of tiny slices. Track each dimension on its own, and cross two only where you suspect an interaction.
- Tagging after the fact by hand, inconsistently. Apply tags when you create a case, using a fixed list. Reject cases with tags outside the list.
Fill gaps
When find_gaps reports a hole, fill it from the sources in the earlier chapter: search production logs for matching inputs, ask a domain expert to write cases, or generate synthetic ones. The next chapter covers doing the last of these safely.
Exercise
Your dataset has 500 cases. 480 are tagged common, 15 are edge, and 5 are adversarial. Overall accuracy is 91%. Why is this number misleading, and what two changes would you make?
Show answer
The common cases make up 96% of the data, so they dominate the average, and the edge and adversarial slices are too small to affect it or to give reliable scores of their own. Report accuracy per slice with case counts, and add more edge and adversarial cases until each reaches a minimum count you can justify.