Sub topic 8
Turning Grades into Metrics
This chapter assumes you already have an evaluation dataset and at least one grader for each important quality dimension. You should also be comfortable reading short Python and JSON snippets. The goal here is to turn individual case grades into numbers that support product decisions.
From individual grades to useful measurements
A grader produces a result for one evaluation case. For example, a groundedness grader might return passed: true, while a human reviewer might assign a score from 1 to 5. A metric aggregates these results across many cases.
The simplest metric is pass rate:
\[ \text{pass rate} = \frac{\text{number of passing cases}}{\text{total cases}} \]
If 92 of 100 cases pass, the pass rate is 92%. This number is useful, but it can hide important information. A feature could pass most general cases while failing every case involving account deletion.
Track metrics by quality dimension and by meaningful slice of the dataset:
- Category, such as billing, returns, or troubleshooting.
- Case type, such as typical, edge, or adversarial.
- Severity, such as minor, major, or critical.
- Customer segment, language, or product version.
- Grader type, such as correctness, safety, or style.
A metric should always state its denominator. “The model had 92% accuracy” is incomplete unless you know which cases were counted and which outputs were considered correct.
A practical aggregation model
Store one result per case. Include the case identifier, dimensions used for filtering, the grader outcomes, and severity. Then calculate overall and sliced metrics from those records.
| Metric | Formula | Useful for |
|---|---|---|
| Pass rate | Passing cases / all cases | Overall quality |
| Failure rate | Failed cases / all cases | Regression tracking |
| Critical failure count | Failed critical cases | Safety and trust gates |
| Slice pass rate | Passing cases in a slice / cases in that slice | Finding uneven performance |
| Average rating | Sum of ratings / rated cases | Human or judge scores |
Do not average percentages from slices unless the slices have equal sizes. Calculate from the underlying case counts instead. Otherwise, a small slice can have the same influence as a large one.
from collections import defaultdict
results = [
{"id": "refund-001", "category": "refund_policy", "type": "typical",
"passed": True, "severity": "minor"},
{"id": "refund-014", "category": "refund_policy", "type": "edge_case",
"passed": False, "severity": "critical"},
{"id": "setup-003", "category": "setup", "type": "typical",
"passed": True, "severity": "minor"},
]
def pass_rate(rows):
if not rows:
return 0.0
return sum(row["passed"] for row in rows) / len(rows)
def metrics_by_category(rows):
groups = defaultdict(list)
for row in rows:
groups[row["category"]].append(row)
return {
category: {
"cases": len(group),
"pass_rate": pass_rate(group),
"critical_failures": sum(
not row["passed"] and row["severity"] == "critical"
for row in group
),
}
for category, group in groups.items()
}
overall = {
"cases": len(results),
"pass_rate": pass_rate(results),
"critical_failures": sum(
not row["passed"] and row["severity"] == "critical"
for row in results
),
}
print(overall)
print(metrics_by_category(results))The output separates volume, quality, and critical risk. That makes it easier to compare releases and investigate changes.
Avoiding misleading summaries
An overall pass rate should not replace failure analysis. A 98% pass rate may still be unacceptable if the two failures expose private data. Severity-weighted scores can help prioritize investigation, but they should not hide critical failures inside an average.
Keep the raw case results alongside every reported metric. Record the dataset version, feature version, grader version, and evaluation date. Without this information, a change in the metric may reflect a changed grader or dataset rather than a changed feature.
Reading metrics over time
Compare the current evaluation with a baseline. Look for both absolute performance and change from the previous version.
- A pass rate that falls from 96% to 91% needs investigation, even if 91% exceeds a broad target.
- A stable overall rate with a falling edge-case rate indicates a hidden regression.
- A small increase in total failures may matter less than one new critical failure.
- A metric based on very few cases should be reported with its case count and treated cautiously.
Metrics tell you where the feature stands. The next step is to define the thresholds that determine whether that result is acceptable.
Exercise
An evaluation has 200 cases. It passes 190 cases, but two of the ten failures are critical. Is a 95% pass rate enough to ship?
Show answer
Not by itself. The release also needs a separate critical-failure rule. If critical failures have zero tolerance, the release must be blocked.