Sub topic 7
Grading Outputs: Code Checks, Human Review, and Model Judges
Assume you understand basic product requirements, evaluation datasets, and Python and JSON syntax. This chapter focuses on selecting a grader, which is a method for deciding whether an AI output meets a requirement.
An AI feature rarely has one correct output string. A useful grader checks the property that matters instead. For example, a support answer may use different words each time but still need to be grounded in the approved policy, include a required warning, and avoid unsupported promises.
Match the grader to the quality dimension
Different quality dimensions require different kinds of evidence.
| Quality dimension | Suitable grader | Example |
|---|---|---|
| Required or forbidden content | Code-based check | Contains a refund link and does not promise a guaranteed refund |
| Exact format or schema | Code-based check | Returns valid JSON with a `category` field |
| Factual support | Human or model-based review | Every claim is supported by retrieved documents |
| Tone and usefulness | Human or calibrated model judge | The answer is clear, respectful, and actionable |
| Safety or policy compliance | Code check plus human review | Does not reveal private data or give prohibited advice |
Start with code whenever the rule can be expressed reliably. Code graders are fast, repeatable, and inexpensive. They are weak when quality depends on meaning, context, or judgment.
def grade_case(case, output):
text = output.lower()
includes_ok = all(term.lower() in text for term in case.get("must_include", []))
excludes_ok = not any(term.lower() in text for term in case.get("must_not_include", []))
return includes_ok and excludes_ok
def run_eval(cases, generate):
results = []
for case in cases:
output = generate(case["input"])
results.append({
"id": case["id"],
"passed": grade_case(case, output),
})
return resultsThis grader checks phrases, not truth. An answer can contain the required words while still giving a misleading explanation. Treat phrase checks as one signal rather than a complete quality evaluation.
Use human review for meaning and risk
Human review is appropriate when the evaluator must interpret context. Reviewers can judge whether an answer actually answers the question, distinguishes known facts from uncertainty, and handles an unusual situation safely.
Give reviewers a rubric, which is a written scoring guide. A useful rubric defines:
- The quality dimension being scored.
- The allowed score values.
- Observable evidence for each score.
- Examples of passing and failing outputs.
- The action required for a critical failure.
For example, a groundedness rubric might score 0 when the answer contradicts the source, 1 when it contains unsupported claims, and 2 when every material claim is supported.
Human review costs more and can vary between reviewers. Reduce variation by training reviewers, hiding system or model identity when practical, and measuring agreement on a shared sample. Do not average away a critical safety failure. Record its severity separately.
Use model judges carefully
A model-based judge is an AI model that evaluates another model's output. It can review qualities such as relevance, completeness, or tone at a larger scale than a human team.
A judge prompt should include:
- The user request.
- The reference answer or source material, when available.
- The output to evaluate.
- A precise rubric.
- A fixed response format, such as a score and reason.
A model judge can inherit biases from its instructions or prefer fluent answers over accurate ones. Calibrate it against human-labeled examples. Compare the judge's decisions with expert decisions, inspect disagreements, and revise the rubric or prompt before using the judge as a release decision.
Combine grades into a decision
Store each case result with its case ID, grader, score, and failure severity. Calculate separate metrics for each quality dimension. An overall average can conceal a serious failure, so pair pass-rate thresholds with zero-tolerance rules for critical errors.
For example, a requirement might demand that at least 95% of refund-policy answers are grounded, while allowing zero answers that contradict a refund deadline. This connects the grader directly to the product requirement.
Exercise
When should you prefer a code-based grader over a model-based judge?
Show answer
Prefer a code-based grader when the rule is objective and reliably expressible, such as schema validity, required fields, forbidden phrases, or an exact safety constraint. Use a model-based judge for context-dependent qualities, and calibrate it against human reviews.