Lesson 18.2 · 2 of 5 · 4 min read · Reviewed 24 Nov 2026
LLM-as-judge and rubrics
By the end, you can
- Use a model as a grader with a clear rubric.
- Write rubrics that give consistent scores.
A grading prompt
You are grading a support reply for one criterion: policy accuracy.
<policy>...</policy>
<customer_message>...</customer_message>
<reply>...</reply>
Rubric:
- pass: every policy fact in the reply matches the policy.
- partial: a minor detail is missing but nothing is wrong.
- fail: any policy fact is wrong or invented.
First write your reasoning in <reasoning>, quoting the relevant policy line.
Then give <verdict>pass|partial|fail</verdict>.
Rules that help
- One criterion per call where possible. Mixed rubricsRubric: A written set of criteria and score levels that a grader applies to each output. blur together.
- Few levels with definitions. Pass, partial, fail beats 1 to 10.
- Reason, then verdict. It improves accuracy and gives you something to read when you disagree.
- Give the graderGrader: The part of an eval that decides whether an output passes, using code, a model or a person. what it needs. For faithfulnessFaithfulness: Whether every claim in an answer is supported by the retrieved context., include the source. For correctness, include the reference answer.
- Structured outputStructured outputs: Making a model return data that matches a defined schema, such as JSON with required fields and types. so verdicts parse reliably.
- Fixed settings (same model, effort and rubric each run) for consistency.
Known biases
Model gradersLLM-as-judge: Using a language model with a rubric to grade another model’s outputs. can prefer longer answers, answers in their own style, and the first of two options (18.4). Calibrate against people (18.3) before trusting scores.
Cost
Grading uses tokens too. Grade with a smaller model where calibrationCalibration: Checking that a grader’s scores agree with expert human judgement, and adjusting it until they do. shows it agrees well, and grade a sample in production rather than everything.
Key points
- An LLM-as-judge reads the input, the output and a rubric, then gives a score and a reason.
- Clear rubrics with concrete levels and examples give far more consistent scores than 'rate 1 to 10'.
- Ask for the reason before the score, use structured output, and grade one criterion per call when you can.
Turn a vague rubric into verdicts
Build a one-criterion grading prompt with defined levels, and parse the judge's verdict reliably.
You will have: A build_prompt() function and a parse_verdict() function tested on four judge replies.
Steps
- Read the policy, the customer message and the reply in the starter.
- Write build_prompt() with tagged inputs, a pass, partial and fail rubric, and reasoning before the verdict.
- Write parse_verdict() to pull the word inside <verdict> tags, or return None if it is missing or not allowed.
- Run the four sample judge replies through the parser and count how many parse.
Done when
- The prompt contains <policy>, <reply>, all three levels and asks for reasoning first.
- 3 of 4 sample replies parse; the 1 to 10 style reply returns None.
Open in the Playground No API key needed.
Starter code (Python)
import re
POLICY = "Footwear may be returned within 30 days if unworn. Sale items are final sale unless faulty."
MESSAGE = "Can I return sale trainers I wore once?"
REPLY = "Sale items are final sale unless they are faulty, so worn sale trainers can't be returned."
ALLOWED = {"pass", "partial", "fail"}
def build_prompt(policy, message, reply):
# TODO: one criterion (policy accuracy), inputs in <policy>, <customer_message>, <reply> tags,
# TODO: define pass, partial and fail, then ask for <reasoning> first and <verdict> last
return "Rate this reply from 1 to 10."
def parse_verdict(text):
# TODO: find <verdict>...</verdict>, lowercase it, return it only if it is in ALLOWED
return None
JUDGE_REPLIES = [
"<reasoning>The reply quotes the sale rule correctly.</reasoning><verdict>pass</verdict>",
"<reasoning>It omits the 30-day window but says nothing wrong.</reasoning><verdict>Partial</verdict>",
"<reasoning>It invents a 60-day window.</reasoning>\n<verdict> fail </verdict>",
"I would give this an 8 out of 10.",
]
print(build_prompt(POLICY, MESSAGE, REPLY))
parsed = [parse_verdict(r) for r in JUDGE_REPLIES]
print("verdicts:", parsed)
print(f"parsed {sum(p is not None for p in parsed)} of {len(parsed)}")
Show a solution
import re
POLICY = "Footwear may be returned within 30 days if unworn. Sale items are final sale unless faulty."
MESSAGE = "Can I return sale trainers I wore once?"
REPLY = "Sale items are final sale unless they are faulty, so worn sale trainers can't be returned."
ALLOWED = {"pass", "partial", "fail"}
def build_prompt(policy, message, reply):
return "\n".join([
"You are grading a support reply for one criterion: policy accuracy.",
f"<policy>{policy}</policy>",
f"<customer_message>{message}</customer_message>",
f"<reply>{reply}</reply>",
"Rubric:",
"- pass: every policy fact in the reply matches the policy.",
"- partial: a minor detail is missing but nothing is wrong.",
"- fail: any policy fact is wrong or invented.",
"First write your reasoning in <reasoning>, quoting the policy line you rely on.",
"Then give <verdict>pass|partial|fail</verdict>.",
])
def parse_verdict(text):
m = re.search(r"<verdict>\s*(\w+)\s*</verdict>", text, re.IGNORECASE)
if not m:
return None
v = m.group(1).lower()
return v if v in ALLOWED else None
JUDGE_REPLIES = [
"<reasoning>The reply quotes the sale rule correctly.</reasoning><verdict>pass</verdict>",
"<reasoning>It omits the 30-day window but says nothing wrong.</reasoning><verdict>Partial</verdict>",
"<reasoning>It invents a 60-day window.</reasoning>\n<verdict> fail </verdict>",
"I would give this an 8 out of 10.",
]
prompt = build_prompt(POLICY, MESSAGE, REPLY)
print(prompt)
print("reasoning asked before verdict:", prompt.index("<reasoning>") < prompt.index("<verdict>"))
parsed = [parse_verdict(r) for r in JUDGE_REPLIES]
print("verdicts:", parsed)
print(f"parsed {sum(p is not None for p in parsed)} of {len(parsed)}")