Sub topic 2
Define the task and what counts as success
This chapter assumes you can read and write basic Python and JSON, and that you have called an LLM API or used an LLM-based app. It also assumes you know what a proportion is. You don't need any evaluation experience.
Every later step in building an evaluation dataset depends on this one. You can't choose cases, write reference answers, or pick a grader until you know what the app is supposed to do and how you would tell that it did it. This chapter turns "the app should work well" into a written task definition and a list of success criteria. Each criterion can be checked on a single case.
Why a vague goal produces a useless dataset
"The support bot should give good answers" sounds like a goal. It can't guide data collection, because two people reading it would collect different cases and grade them differently. The score you computed would also not say anything you could act on.
A task definition removes that ambiguity. It forces decisions that otherwise get made silently and inconsistently later:
- Which inputs are in scope, and which should the app decline?
- What does a correct output contain, and what must it never contain?
- Who decides when two acceptable answers differ?
- Which failures are tolerable, and which are not?
Writing these down also makes the dataset reviewable. A teammate can disagree with a criterion, and you can fix it once instead of discovering the disagreement in the labels.
Write the task as a contract
Describe the app as a function with a stated contract. Four parts are enough for most apps.
- Input. What the app receives: a single user message, a conversation, a document plus a question, structured fields. Include the context the app sees, such as retrieved passages or user metadata, because the dataset must reproduce it.
- Output. What the app returns: free text, a label, JSON that must match a schema, a tool call.
- Scope. The inputs the app should handle, and the inputs it should refuse or redirect. Out-of-scope behavior is part of the task, not an exception to it.
- Constraints. Rules that hold on every output, such as length limits, language, tone, no legal advice, no invented citations.
For a customer support assistant about returns, the contract might read: the input is one customer message plus the retrieved policy excerpt. The output is a short plain-text answer. In scope are questions about returns, refunds, and exchanges. Anything else gets a polite redirect to a human agent. The answer must stay under 80 words and must never promise a refund, because only agents can approve one.
From goals to checkable criteria
A success criterion is a statement about one output that a person or a program can mark pass or fail without guessing. The test is simple: could two reviewers who read only the criterion, the input, and the output reach the same verdict?
Compare these:
| Vague goal | Checkable criterion |
|---|---|
| Answers are accurate | The yes/no verdict matches the policy for this input |
| Answers are concise | The output is at most 80 words |
| The bot is safe | The output never states or implies a refund has been approved |
| The bot stays on topic | Out-of-scope inputs get a redirect and no policy claims |
| Tone is professional | A rubric of three listed properties, each marked present or absent |
The last row shows that subjective qualities can still be made checkable. Break them into observable properties. "Professional tone" becomes "no slang, no blame toward the customer, an apology only when the policy denies the request". If you can't break a quality down this way, you can't measure it yet, and the criterion needs more thought before it goes in the dataset.
Kinds of criteria
Most LLM apps need criteria from several of these groups:
- Correctness. The answer agrees with the facts or the reference.
- Format. The output parses, matches a schema, or fits a length limit.
- Grounding. Claims are supported by the provided context, with no invented details.
- Policy and safety. The output avoids forbidden content or commitments.
- Behavior on out-of-scope input. The app refuses or redirects as specified.
- Style. Tone, reading level, language.
Latency and cost matter too, but they are properties of a run, not of the answer's content. Track them alongside the dataset, and don't mix them into per-case pass/fail.
Hard constraints and graded qualities
Split criteria into two tiers. Hard constraints must hold on every case. Any single violation counts as a failure, whatever else the answer got right. "Never promise a refund" is an example. Graded qualities are things you want more of, and a score can reasonably fall short of perfect. Helpfulness and completeness are examples.
Keeping the tiers separate prevents a common error: averaging everything into one number. If an app scores 95% overall but breaks a hard constraint on 3% of cases, the average hides the part that matters. Report hard-constraint violations as their own rate.
A worked example in code
Writing the criteria as code is a good test of whether they are really checkable. The sketch below encodes the three criteria that a program can decide for the returns bot. Each check takes the model's output and the case, and returns pass or fail.
import re
PROMISE = re.compile(
r"\b(we will refund|i have refunded|your refund (has been|is) (approved|issued))\b",
re.IGNORECASE,
)
def verdict(output):
text = output.strip().lower()
if text.startswith("yes"):
return "yes"
if text.startswith("no"):
return "no"
return "unclear"
def check_case(output, case):
return {
"verdict_matches": verdict(output) == case["expected_verdict"], # graded quality
"within_length": len(output.split()) <= 80, # hard constraint
"no_refund_promise": PROMISE.search(output) is None, # hard constraint
}
case = {"input": "Can I return a laptop after 45 days?", "expected_verdict": "no"}
good = "No. Returns are accepted within 30 days of delivery."
bad = "Yes, we will refund you today."
print(check_case(good, case))
print(check_case(bad, case))Running it prints {'verdict_matches': True, 'within_length': True, 'no_refund_promise': True} for the good answer. The bad answer gets verdict_matches of False and no_refund_promise of False, so it fails on correctness and on a hard constraint.
Notice what the exercise of writing this revealed. The verdict function assumes answers start with "yes" or "no", so the task definition should say so, or the check will mark valid answers "unclear". Notice also that the case needed an expected_verdict field, which the next chapter builds into the schema. Success criteria drive the schema, not the other way around.
The task definition as a pipeline step
The diagram shows how a vague goal becomes something the rest of the process can use.
Edge cases and common errors
Criteria that need the whole conversation. In a multi-turn app, a single reply may be fine while the conversation fails. Decide whether a case is one turn or a full dialogue, and define the unit you grade. Mixing the two makes scores hard to read.
Several valid answers. If many outputs are acceptable, an exact reference answer will mark good outputs wrong. Write the criterion as properties the answer must have, such as the correct verdict and a mention of the 30-day window, rather than as one string to match.
Out-of-scope input treated as noise. Teams often leave refusals and redirects out of the task definition, then find the app answers legal questions with confidence. Make out-of-scope behavior an explicit criterion.
Measuring what is easy instead of what matters. Length and format are easy to check, so they end up dominating the score. Start from the failures that would hurt users, then find a way to check those.
Criteria that disagree with each other. "Be brief" and "always explain the reasoning" conflict. Rank them, or state which wins, before you collect data.
Skipping the cost of errors. A false approval of a refund is worse than a false denial that a human can reverse. Say which direction of error you care about. It decides which hard constraints exist and what pass rate you will accept.
Drift. Criteria change when the product changes. Date the task definition and keep it with the dataset, so old scores can be read against the rules that applied when they were produced.
Set the acceptance bar now
Decide what result would count as good enough before you see any scores. For example: zero tolerance on hard constraints in the test split, and at least 90% correct verdicts overall with no slice below 80%. Choosing thresholds after seeing results invites rationalizing whatever number you got. Later chapters show how to put uncertainty around these numbers, so treat the bar as a target that you will revisit once you know how precise your scores are.
Exercise
A summarization app must "produce a good summary of a support ticket". Rewrite this goal as one hard constraint and two graded qualities, each checkable on a single output.
Show answer
One valid answer. Hard constraint: the summary contains no customer personal data such as email addresses or phone numbers, and it is at most 60 words. Graded quality 1: the summary names the customer's main problem, marked present or absent against a reference list of key facts. Graded quality 2: it states the requested resolution if the ticket gives one, marked present or absent. Each is decidable by two reviewers who read only the criterion, the ticket, and the summary.
Exercise
A chatbot scores 96% on an averaged "quality" metric that combines correctness, tone, and a rule against giving medical advice. Why is this number a poor basis for a release decision, and what should you report instead?
Show answer
The average can hide violations of the medical-advice rule, which is a hard constraint. A few such failures barely move a 96% average but may be unacceptable. Report the hard-constraint violation rate separately, with a target of zero or a stated tolerance, and report the graded qualities on their own.