Sub topic 2
Defining what good looks like
This chapter assumes you can write basic Python, have called an LLM through an API, and know what a pass rate is. It covers the step before any metric exists: deciding, in writing, what a correct output is for your application. The later chapters on datasets, harnesses, and judges all depend on these decisions.
Why "good" has to be defined first
Teams often start by picking a metric, such as BLEU, a judge prompt, or a thumbs-up rate. Then they find out the number doesn't track what users care about. A metric can only measure what you told it to measure. If you haven't written down what good means, the metric will quietly define it for you.
Defining success criteria also stops you from improving the wrong thing. A summarizer can get more fluent while becoming less faithful. A support bot can get friendlier while giving wrong refund amounts. Without separate criteria, a rise in one number hides a drop in another.
Start from the task and the user
Write the answer to three questions before anything else:
- Who uses the output? A customer reading a chat reply has different needs than a downstream program parsing JSON.
- What decision or action follows? If a wrong answer causes a refund, a medical mistake, or a failed pipeline run, the bar is higher.
- What would a careful human expert accept? This gives you a concrete reference for "good enough".
Take a support assistant that answers questions from a product manual. The task sounds simple, but the user cares about several separate things: the answer is correct, it comes from the manual, it is short enough to read, and it doesn't promise things the company doesn't offer. Each of these is its own criterion.
Failure modes come before metrics
A failure mode is a specific, named way the system can be wrong. List them by looking at real or realistic outputs, not by guessing in the abstract. Run your prompt on 20 to 30 varied inputs and read every output. You will see patterns quickly.
For the support assistant, a first list might be:
- States a fact that is not in the manual (fabrication).
- Answers a different question than the one asked.
- Gives a correct answer but omits a required warning.
- Returns a reply in the wrong language.
- Answers confidently when the manual has no relevant section, instead of saying so.
- Breaks the required output format, so the UI fails to render it.
Each failure mode then maps to one or more criteria. "Fabrication" becomes "every claim is supported by the retrieved text". "Wrong language" becomes "the reply language matches the question language".
Properties of a usable criterion
A criterion is usable when two people, or a person and a program, would score the same output the same way. Check each one against this list.
- Specific. "High quality" is not a criterion. "Mentions the refund window and its length in days" is.
- Observable in the output. You must be able to judge it from the text, the context, and the expected answer. "The user feels satisfied" is not observable offline.
- One dimension per criterion. "Accurate and concise" hides two failures behind one score. Split it.
- Tied to a failure mode or a user need. If no one would be harmed when it fails, drop it.
- Scorable by a known method. You should be able to say whether a rule, a reference comparison, a judge, or a human will score it.
Hard constraints and soft qualities
Separate criteria into two groups, because they are handled differently.
| Kind | Meaning | Typical examples | Release rule |
|---|---|---|---|
| Hard constraint | Must hold on essentially every output | Valid JSON, no leaked personal data, no banned claims | Threshold near 100%, any failure is investigated |
| Soft quality | Matters in degree, trades off against others | Helpfulness, tone, completeness, brevity | Threshold on an average or pass rate, tracked over time |
Hard constraints are usually checked with deterministic code, which a later chapter covers. Soft qualities usually need a reference, a judge, or human review. Mixing the two in a single averaged score is a common mistake. A system that returns broken JSON on 5% of requests is not "95% good" if each broken response crashes a downstream job.
Choose a scale that people can apply consistently
Scales affect how reliable your scores are, so choose one deliberately.
- Binary pass/fail is the easiest to apply consistently and to analyze. Prefer it whenever the criterion can be phrased as a yes/no question.
- Ordinal scales (1 to 5) work when degree matters, but raters spread across the middle, and the difference between a 3 and a 4 is rarely defined. If you use one, write an anchor description for every level.
- Pairwise preference ("which of these two outputs is better?") is often easier for humans and judges than absolute scoring. It suits comparing two versions, but it doesn't tell you whether either version is good enough to ship.
For most application work, a set of binary criteria is a good default. You can report each one separately and also report the fraction of cases where all required criteria pass.
Set thresholds before you see the results
A threshold is the score that separates acceptable from not acceptable. Pick it before running the evaluation on the new version. If you choose it afterward, you will be tempted to set it just below whatever you got.
Base thresholds on something real:
- The current system's performance, if one exists. "No worse than production" is a defensible starting point.
- Human performance on the same cases. If two experts agree 90% of the time, demanding 99% from the model is not meaningful.
- The cost of each failure. A cosmetic tone issue can tolerate a lower threshold than a wrong dosage.
You can encode the criteria and thresholds as data so they are reviewed, versioned, and used by the harness.
from dataclasses import dataclass
@dataclass(frozen=True)
class Criterion:
name: str
description: str
kind: str # "hard" or "soft"
method: str # "rule", "reference", "judge", or "human"
threshold: float # minimum acceptable pass rate, from 0 to 1
CRITERIA = [
Criterion("valid_json", "Reply parses as JSON with the required keys",
"hard", "rule", 0.99),
Criterion("grounded", "Every claim is supported by the retrieved manual text",
"hard", "judge", 0.95),
Criterion("correct_answer", "Final answer matches the reference answer",
"soft", "reference", 0.85),
Criterion("polite_tone", "Reply is courteous and avoids blame",
"soft", "judge", 0.80),
]
def check_release(scores: dict, criteria=CRITERIA) -> list:
"""Return a list of human-readable failures. An empty list means ship."""
failures = []
for c in criteria:
value = scores.get(c.name)
if value is None:
failures.append(f"{c.name}: no score recorded")
elif value < c.threshold:
failures.append(f"{c.name}: {value:.2f} is below {c.threshold:.2f}")
return failures
scores = {"valid_json": 1.0, "grounded": 0.92, "correct_answer": 0.88}
for line in check_release(scores):
print(line)This prints two lines: grounded: 0.92 is below 0.95 and polite_tone: no score recorded. Treating a missing score as a failure matters. Otherwise a criterion that silently stopped being measured looks like a pass.
Common mistakes
- Using a proxy as the goal. Output length, similarity to a reference, or a judge's overall score is only a stand-in. Check periodically that it still correlates with what users want.
- A single overall score. It hides trade-offs and makes regressions invisible. Keep per-criterion results.
- Criteria nobody can score. If your team can't agree on 10 sample outputs, the criterion is too vague. Rewrite it with an example of a pass and a fail.
- Ignoring the "should refuse or say I don't know" cases. A system that always answers can look excellent on answerable questions. Include criteria for correct abstention.
- Freezing the criteria. Real traffic reveals failure modes you did not predict. Revisit the list after each round of error analysis.
How the pieces connect
The flow runs from the task to scoring methods. Each step narrows the one before it.
Putting it into practice
Use this sequence for any new application:
- Write a one-paragraph description of the task, the user, and the cost of a wrong answer.
- Collect 20 to 30 realistic inputs and read the outputs from your current prompt.
- List every failure you see, and add the ones you fear but have not yet seen.
- Turn each failure into a criterion with a pass and fail example.
- Mark each as hard or soft, choose a scale, and assign a scoring method.
- Set thresholds from a baseline or human agreement, and record them before testing the next version.
This document is short, but every later step depends on it. The dataset you build next should cover each failure mode, and the harness should report each criterion separately.
Exercise
A team builds an assistant that extracts invoice totals into JSON for an accounting system. Their only metric is a 1 to 5 "overall quality" rating from a judge model, and the average is 4.3. List two criteria they should define instead, say whether each is hard or soft, and say how each could be scored.
Show answer
Valid JSON with the required fields is a hard constraint, scored by a deterministic rule (parse and check the schema), with a threshold near 100% because a malformed reply breaks the accounting system. The extracted total equals the true total is also hard, because a wrong amount causes a financial error. It is scored by comparing against a reference value from labeled invoices, with a threshold set from the cost of errors and human agreement on the same invoices. A soft example would be "includes a short note when the invoice is ambiguous", scored by a judge or human. The single 4.3 average hides both failures, so none of these can be seen in it.