Use a Model as a Grader
Some things about an answer can be checked with a few lines of code: a required phrase, a forbidden word, the value of a field. Others depend on meaning, such as whether every claim in the answer is backed by the text it was supposed to come from. For those, you can ask a second language model to read the answer and judge it against a rule you write down. This page explains how to set up such a model grader so its verdicts are useful, and the ways it can still be wrong.
A model that grades another model
Picture a support assistant for a train company. A customer asks whether an Advance ticket can be refunded, and the assistant answers from the company's ticket policy. The policy says Advance tickets cannot be refunded. The answer says they can be refunded "within 14 days, minus a small fee". The answer is polite, fluent and wrong in a way that matters.
A code grader struggles here. It could search for the word "refund", but the correct answer and the wrong one both contain it. It could compare the answer with a reference sentence, but a correct answer can be worded in many ways. What you really want to ask is does the policy support every claim this answer makes?, and answering that means reading both texts and understanding them.
A model grader does exactly that reading. You send a language model a prompt that holds the rule to judge by (the criterion), together with the customer's question, the assistant's answer and the policy text. The model replies with a short reason and a verdict, and your code collects the verdicts like any other grader's results. The practice is widely called LLM-as-a-judge, and the grading model is called the judge.
- Criterion the rule to judge by
- Question, answer, source what is judged
- Judge model one call per answer
- Reason, then verdict pass or fail
- Criterion to Judge model
- Question, answer, source to Judge model
- Judge model to Reason, then verdict
The flexibility has a price. Every verdict is one model call, so grading a few hundred answers means a few hundred calls: they take time, they usually cost money, and the judge can make mistakes of its own. A code check, by contrast, is free to run, instant and gives the same result every time. That is why practitioners keep the order simple: first ask whether code can decide the question, and reach for a model only when the judgment needs understanding.
| Aspect | Code grader | Model grader |
|---|---|---|
| What it can decide | Text, fields, format, length | Meaning: support, tone, relevance |
| Cost per verdict | Practically nothing | One model call |
| Speed | Instant | Much slower |
| Same input, same verdict | Always | Not guaranteed |
| Can be trusted when | The code is correct | It has been checked against human labels |
True or false?
Once a model grader is set up, it is a good idea to move the code checks into it as well, so everything is graded in one place.
False. Code checks are faster, cheaper and give the same verdict every time. A model grader is kept for what code cannot decide, not used in place of code that already works.
A model grader can judge whether an answer is supported by a source text even when the answer is worded quite differently from that text.
True. That is the reason to use one: the judge reads for meaning, so a correct paraphrase can pass where a strict text match would fail it.
One criterion, judged pass or fail
It is tempting to write one judge that rates an answer on everything at once: correct, helpful, polite, concise. A judge like that is hard to make reliable, and its result is hard to use. When it gives a low mark, you do not know which quality went wrong. Judges do better when each prompt scores a single dimension, so the usual design is one judge per failure mode: one judge asks only whether the claims are supported by the policy, another (if you need it) asks only whether the tone is rude.
The verdict itself works best as a plain pass or fail, not a score from 1 to 5. A scale feels more informative, but in practice it causes three problems:
- The points are vague. Nobody can say exactly what separates a 3 from a 4, and different people (and different runs of a judge) read the scale differently.
- The middle attracts. Raters drift towards middle values to avoid a hard decision, so many answers end up with an uninformative 3.
- A score is hard to act on. A pass rate tells you how many answers had the problem. An average of 3.6 does not tell you what to fix, and to show that a change of a few tenths is real you need more samples.
A binary verdict forces you to decide where the line is, and to write that line down. It also makes the judge easy to check: a person can label the same answers pass or fail, and you can count where the judge and the person disagree. If you want to track gradual progress, add another binary check for another specific quality rather than widening the scale.
| Answer | Score 1 to 5 | Supported by the policy? |
|---|---|---|
| Says Advance tickets cannot be refunded | 4 | pass |
| Says Advance tickets can be refunded within 14 days | 3 | fail |
| Correct, but adds a fee the policy never mentions | 3 | fail |
In the table, the scores 3 and 4 sit close together even though one answer is fine and two give the customer false information. The pass or fail column says what happened, and the two fails are exactly the cases someone needs to look at.
True or false?
A score from 1 to 5 is easier to compare with a person's judgment than a pass or fail verdict.
False. People disagree about adjacent points on a scale, so there is no clear reference. With pass or fail, judge and person either agree on an answer or they do not, and the disagreements are easy to count and read.
A judge that checks only whether claims are supported by the policy should pass a rude answer whose claims are all correct.
True. A judge scoped to one criterion ignores everything else. Rudeness is a different failure mode and gets its own check.
What a judge prompt holds
The judge knows only what its prompt tells it. A vague instruction such as "is this answer good?" leaves it to invent its own standard, and that standard will not be yours. A good judge prompt is closer to the written instructions you would give a new colleague who has to grade answers for you. It holds four things:
- The criterion: the one question being judged, stated in a sentence.
- A precise definition of pass and of fail, including the borderline cases you have already met: does an answer that says "I don't know" pass? Does a claim that follows directly from the policy, without being written in it, count as supported?
- A few worked examples: real answers with a short critique and the verdict, so the judge sees where the line falls. Good examples are taken from answers you have already reviewed, which is why you cannot write a good judge prompt before you have looked at real outputs.
- Everything the judgment needs: the question, the answer, and for a support criterion the source text itself. A judge asked whether an answer matches the policy cannot decide without the policy in front of it.
Putting each piece of input inside its own named tags, such as <policy> and <answer>, keeps them apart, so the judge does not confuse the answer it is grading with the examples or the instructions.
You grade one answer written by a train company's support assistant.
Criterion: every factual claim in the answer is supported by the
ticket policy given in <policy>.
PASS: each claim about refunds, time limits, fees or conditions is
stated in the policy or follows directly from it. An answer that
says it does not know, or refers the customer to staff, passes.
FAIL: the answer makes at least one claim the policy does not
contain or contradicts, for example a different time limit or a
fee the policy never mentions.
Judge only this criterion. Tone, length and politeness do not matter.
<examples>
Answer: "Anytime tickets can be refunded up to 28 days after travel."
Critique: The policy gives the same 28-day limit for Anytime tickets.
Verdict: pass
Answer: "Advance tickets can be refunded within 14 days."
Critique: The policy says Advance tickets cannot be refunded at all.
Verdict: fail
</examples>
First list the claims in the answer and check each one against the
policy. Then give your verdict.The question, the answer and the policy arrive in a second message, each in its own tag. The prompt stays the same for every answer; only that second message changes.
True or false?
If the criterion is clear enough, the judge does not need to see the policy text to decide whether an answer agrees with it.
False. Without the source, the judge can only guess from general knowledge. Giving a judge the material its decision depends on, such as a reference or a source text, makes it much more accurate.
Reason first, verdict second
A language model writes its reply one piece at a time, and each piece is shaped by what it has already written. That makes the order of the reply matter. If the judge writes "fail" first and its reason after, the reason can only justify a verdict that is already fixed. If it writes the reason first, listing the claims and checking each against the policy, the verdict comes at the end and is based on that work. Asking a grader to reason before it decides measurably improves its judgments, especially on cases that need care.
The reply also has to be something your code can read without guessing. The cleanest way is structured output: you send a JSON schema with the request, and a provider that supports it constrains the reply to that shape. The schema also settles the order. With OpenAI's Structured Outputs, the fields are produced in the order the schema lists them; that is a promise of OpenAI's API, not of the openai package, and other providers reached through the same package do not all keep it, so check yours. Listing reason before verdict therefore makes the model write its reasoning first. Inside the schema, an enum limits the verdict to exactly two values.
import json
VERDICT_SCHEMA = {
"type": "object",
"properties": {
"reason": {"type": "string"},
"verdict": {"type": "string", "enum": ["pass", "fail"]},
},
"required": ["reason", "verdict"],
"additionalProperties": False,
}
def judge(client, model, judge_prompt, question, answer, policy):
case = (
f"<policy>\n{policy}\n</policy>\n"
f"<question>\n{question}\n</question>\n"
f"<answer>\n{answer}\n</answer>"
)
reply = client.chat.completions.create(
model=model,
messages=[
{"role": "system", "content": judge_prompt},
{"role": "user", "content": case},
],
response_format={
"type": "json_schema",
"json_schema": {
"name": "verdict",
"strict": True,
"schema": VERDICT_SCHEMA,
},
},
)
result = json.loads(reply.choices[0].message.content)
if result.get("verdict") not in ("pass", "fail"):
raise ValueError(f"unexpected judge reply: {result}")
return resultThe function builds the case message and sends it, with the judge prompt as the system message. The reply carries a JSON string in choices[0].message.content, and the function parses it. The schema follows the rules of strict mode: every property is listed as required, and additionalProperties is false.
The result is a dictionary such as {"reason": "...", "verdict": "fail"}, so the rest of your code treats it like the result of any other grader. It counts the fails and keeps the reason beside each one. That reason is what you read when a verdict surprises you.
Not every provider or local model server offers schema-constrained output. Some offer only a JSON mode, which guarantees valid JSON but not your fields; some offer neither. The check before the return is there for that reason: whatever the provider promises, the code makes sure the verdict is one of the two allowed values before trusting it, and stops with an error otherwise. Calls can also fail or be refused, so a grader run should report such cases instead of quietly counting them as passes.
True or false?
Asking the judge for its verdict first and its explanation second gives the same verdicts as the reverse order, just with the text rearranged.
False. The model writes in order, and each part depends on what came before. A verdict written first is decided without any reasoning; the explanation after it can only defend that verdict.
A reply that is valid JSON is not necessarily a reply your code can use.
True. Valid JSON may still lack the verdict field or contain a value such as "partly". Only a schema the provider enforces, or your own check of the parsed reply, guarantees the shape.
How a judge can be wrong
A judge is a language model, so it has the same kinds of errors as the model it grades. Its verdicts are measurements made with an imperfect instrument, and the known weaknesses tell you where to look for mistakes.
| Weakness | What it looks like | What helps |
|---|---|---|
| Favours longer answers | A long, detailed answer passes although it contains an unsupported claim | Say in the prompt that length does not matter; include a long failing example |
| Verdict changes between runs | The same answer passes on one run and fails on the next | Grade a sample twice and compare; record verdicts once and reuse them |
| May favour its own writing | Answers written by the same model are judged more kindly | Check against human labels; try a different judge model if agreement is poor |
Longer answers look better
Judges tend to prefer long, detailed answers, even when the extra length adds nothing or hides a mistake. This is called verbosity bias. In the study that named LLM-as-a-judge, researchers padded answers with a reworded copy of their own content, and some judges preferred the padded version in over 90% of the tests; the strongest judge in the study was fooled far less often. For a support criterion the danger is concrete: a thorough-sounding answer with one invented fee in the middle of it is easy to wave through.
The same answer, a different verdict
Ask the judge about the same answer twice and you may get two different verdicts. Setting the temperature (the setting that controls how much randomness goes into the model's choice of words) to 0 reduces the variation but does not remove it: providers state that identical inputs can still produce different outputs. Some offer a seed setting, which is only a best effort. Answers that sit close to the line between pass and fail are the ones that flip.
- pass run 1
- pass run 2
- fail run 3
- pass run 4
- fail run 5
Because of this, a pass rate from a judge carries some noise of its own. Recording the verdicts once and grading from the saved file gives you a stable number to compare later; running the judge twice over a sample shows how much its verdicts wander.
A judge may prefer its own writing
A judge may rate answers written by the same model more highly than people would, a tendency called self-preference or self-enhancement bias. The evidence is mixed. In one study, some judges favoured their own answers while another did not, and the authors could not settle the question. Later work found that models which recognise their own text more easily also favour it more. Because of this risk, some teams grade with a different model from the one that wrote the answers, and some guides recommend it. Others find the same model is usually fine, since judging an answer against a policy is a different task from writing one.
Every one of these weaknesses leads to the same practical rule: a judge is not trusted because it sounds confident or because judges did well in a published study. It is trusted after its verdicts have been compared with a person's pass or fail labels on the same answers.
True or false?
With the temperature set to 0, a judge always gives the same verdict for the same answer.
False. Temperature 0 makes the output less random but not fully deterministic. Identical requests can still return different replies, and borderline answers are the ones most likely to flip.
Telling the judge that length does not matter, and showing it a long answer that fails, are reasonable defences against verbosity bias.
True. The judge follows its definitions and examples. A long failing example shows it that thoroughness is not the criterion, though only a comparison with human labels shows whether the defence worked.
Research has shown that a judge always favours answers written by its own model, so the judge must be a different model.
False. The evidence is mixed. Self-preference is a known risk that some teams avoid by using a different model, but whether it matters for your judge is something to measure, not a fixed rule.