Self-grade a written answer against a rubric
Evaluate a written exam answer against detailed rubric criteria, reduce score variance with level descriptions, and verify evidence quotes using Python.
Preparing for written or essay examinations is challenging when you have a grading rubric but cannot objectively determine which score tier your draft satisfies.
This post writes out explicit requirements for each performance level and requires the model to quote the student answer verbatim as evidence. A short rubric with criterion names only was not compared in this run. This quote verification approach is similar to Verifying quotes in Claude summaries.
According to Anthropic's guide on reducing hallucinations, grounding model outputs in direct citations makes decisions auditable, and comparing multiple runs of the same prompt (Best-of-N) exposes inconsistent judgments.
[1] Prepare the question, rubric, and student answer. This example uses a 10-point environmental geography question on the Urban Heat Island (UHI) effect.
Question: Explain two primary causes of the Urban Heat Island (UHI) effect, and propose one urban planning measure to mitigate it. (Total: 10 points) Criterion 1: Anthropogenic Heat Emission (3 points)- High (3 pts): Clearly explains the mechanism of anthropogenic heat emissions (e.g., HVAC systems, vehicle traffic).- Medium (2 pts): Mentions artificial heat but the explanation is somewhat abstract or incomplete.- Low (1 pt): Mentions heat emissions without detailed explanation.- Unsatisfactory (0 pts): Fails to identify anthropogenic heat. Criterion 2: Surface Cover and Reduced Vegetation (3 points)- High (3 pts): Clearly explains how impermeable surfaces (asphalt, concrete) and loss of vegetation cause excessive heat absorption and thermal storage.- Medium (2 pts): Mentions surface changes or green space loss but explanation of heat absorption is insufficient.- Low (1 pt): Merely lists surface materials without explanation.- Unsatisfactory (0 pts): Fails to identify surface cover or vegetation loss. Criterion 3: Urban Planning Mitigation Measure (3 points)- High (3 pts): Clearly proposes a feasible spatial mitigation measure (e.g., green roofs, wind corridors) and explains its mechanism.- Medium (2 pts): Proposes a measure but lacks concrete implementation details or mechanism.- Low (1 pt): Slogan-level or unrealistic proposal.- Unsatisfactory (0 pts): Fails to propose a mitigation measure. Criterion 4: Coherence and Sentence Structure (1 point)- High (1 pt): Logical flow is clear and sentences are well-structured.- Low (0 pts): Illogical flow or fragmented sentences.The draft response written by the student:
The urban heat island effect is primarily caused by anthropogenic heat emissions from vehicle traffic and HVAC systems. Additionally, replacing natural vegetation with impermeable asphalt and concrete surfaces increases solar heat absorption and thermal storage. To mitigate this problem, cities should implement extensive green roof initiatives and urban wind corridors to lower thermal mass and improve ventilation.[2] Build the prompt. Separate the rubric and student response with XML tags, enforce verbatim quote extraction, and require Markdown table output.
Grade the student's written response strictly according to the rubric below. <rubric>{rubric.txt content}</rubric> <student_answer>{answer.txt content}</student_answer> Rules:1. Grade strictly according to the level definitions in the rubric. Do not assume or award points for unstated ideas.2. In the "Quote" column, provide the exact verbatim excerpt from <student_answer> used as evidence. If there is no evidence, output exactly "None".3. Output only the Markdown table below without any conversational filler or introductory remarks.4. The final row must contain the total points and maximum points. | Criterion | Max | Score | Level | Quote | Feedback |[3] Run the prompt. Disable tool access with --tools "" to ensure a clean evaluation run.
$ claude -p --model claude-sonnet-5-5 --max-turns 1 --tools "" --setting-sources "" --strict-mcp-config < run/grade-en.prompt.txt > run/grade-en-1.out.txt$ cat run/grade-en-1.out.txt| Criterion | Max | Score | Level | Quote | Feedback ||---|---|---|---|---|---|| Anthropogenic Heat Emission | 3 | 2 | Medium | "anthropogenic heat emissions … | Names specific sources (vehicl … || Surface Cover and Reduced Vegetation | 3 | 3 | High | "replacing natural vegetation … | Links vegetation loss and impe … || Urban Planning Mitigation Measure | 3 | 2 | Medium | "cities should implement exten … | Proposes feasible spatial meas … || Coherence and Sentence Structure | 1 | 1 | High | "Additionally, replacing natur … | Clear, logical progression fro … || **Total** | **10** | **8** | | | |The actual run was made from an empty folder outside the repository. In this table a … at the end of a cell marks a cut made here to fit the page; the cells in the file are longer, and the ellipsis is not the model's.
The model scored 8 out of 10 points. Criterion 1 lost a point because the table says the answer does not explain how waste heat reaches the air, and Criterion 3 was rated Medium for thin implementation detail.
[4] Compare score consistency across three runs.
Running the identical prompt three times yielded the following scores per criterion:
| Run | Criterion 1 (3) | Criterion 2 (3) | Criterion 3 (3) | Criterion 4 (1) | Total (10) |
|---|---|---|---|---|---|
Run 1 (grade-en-1.out.txt) | 2 (Medium) | 3 (High) | 2 (Medium) | 1 (High) | 8 pts |
Run 2 (grade-en-2.out.txt) | 2 (Medium) | 3 (High) | 3 (High) | 1 (High) | 9 pts |
Run 3 (grade-en-3.out.txt) | 2 (Medium) | 3 (High) | 2 (Medium) | 1 (High) | 8 pts |
Criteria 1, 2, and 4 were consistent across all 3 runs. Criterion 3 fluctuated between Medium (2 pts) and High (3 pts), demonstrating why Best-of-N comparison is required for borderline descriptions.
[5] Check the table with a Python script. It checks that no score exceeds its maximum, that the item scores add up to the total row, that no criterion appears twice, and that each quote appears verbatim in the student answer. A quote of None with a score above 0 counts as a failure. A quote ending in an ellipsis passes if the part before it (10 characters or more) is in the answer. It does not check whether the level matches the score or whether a quote is enough to justify the score.
#!/usr/bin/env python3"""usage: check_rubric.py <prompt.txt> <out.txt>"""import sys, re def norm(s): return " ".join(s.replace("`", "").replace('"', "").replace("'", "").split()) src = open(sys.argv[1], encoding="utf-8").read()m = re.search(r"<student_answer>(.*?)</student_answer>", src, re.S)ans = norm(m.group(1) if m else src)rows = [[c.strip().strip("*").strip() for c in l.strip().strip("|").split("|")] for l in open(sys.argv[2], encoding="utf-8") if l.strip().startswith("|")]rows = [r for r in rows if not set("".join(r)) <= set("-: ")][1:]total = [r for r in rows if r[0] in ("합계", "총점", "Total")]items = [r for r in rows if r not in total] err, seen, sum_max, sum_got = 0, set(), 0, 0for n, r in enumerate(items, 1): if len(r) != 6 or not (re.fullmatch(r"\d+", r[1]) and re.fullmatch(r"\d+", r[2])): print(f"FAIL {n}: bad row {r[:3]}"); err += 1; continue crit, mx, got, q = r[0], int(r[1]), int(r[2]), norm(r[4]) sum_max += mx; sum_got += got problems = [] if crit in seen: problems.append("duplicate criterion") seen.add(crit) if got > mx: problems.append(f"score {got} > max {mx}") if q in ("없음", "None", "-", ""): if got > 0: problems.append("score > 0 with no quote") elif q not in ans: pre = q.rstrip(".… ") if not (q != pre and len(pre) >= 10 and pre in ans): problems.append(f"quote not found: {q!r}") print(("FAIL" if problems else "OK "), f"{n}: {crit} {got}/{mx}", "; ".join(problems)) err += bool(problems) if len(total) != 1: print(f"FAIL total rows: {len(total)}"); err += 1else: t = [re.sub(r"\D", "", c) for c in total[0][1:3]] ok = t == [str(sum_max), str(sum_got)] print("OK " if ok else "FAIL", f"total row {t[1]}/{t[0]} vs sum {sum_got}/{sum_max}") err += not oksys.exit(1 if err else 0)Execute the verification script against the Run 1 output.
$ python run/check_rubric.py run/grade-en.prompt.txt run/grade-en-1.out.txtOK 1: Anthropogenic Heat Emission 2/3 OK 2: Surface Cover and Reduced Vegetation 3/3 OK 3: Urban Planning Mitigation Measure 2/3 OK 4: Coherence and Sentence Structure 1/1 OK total row 8/10 vs sum 8/10[6] Test deliberate validation errors and evaluate missing elements.
Four hand-edited files test the script, and all exit with code 1: an invented quote in Criterion 2 (grade-bad-quote-en.out.txt), a total row of 9 (test-total-en.out.txt), a Criterion 1 score of 4 against a maximum of 3 (test-over-en.out.txt), and a repeated Criterion 2 row (test-dup-en.out.txt). The invented-quote result follows (not model output).
$ python run/check_rubric.py run/grade-en.prompt.txt run/grade-bad-quote-en.out.txtOK 1: Anthropogenic Heat Emission 2/3 FAIL 2: Surface Cover and Reduced Vegetation 3/3 quote not found: 'planting urban forests to provide natural shade across downtown'OK 3: Urban Planning Mitigation Measure 2/3 OK 4: Coherence and Sentence Structure 1/1 OK total row 8/10 vs sum 8/10Next, test model sensitivity with an incomplete answer (run/grade-en-omit.prompt.txt) that omits Criterion 2 entirely.
$ claude -p --model claude-sonnet-5-5 --max-turns 1 --tools "" --setting-sources "" --strict-mcp-config < run/grade-en-omit.prompt.txt > run/grade-en-omit.out.txt$ grep -E 'Surface|Total' run/grade-en-omit.out.txt| Surface Cover and Reduced Vege … | 3 | 0 | Unsatisfactory | None | No mention of impermeable surf … || **Total** | **10** | **4** | | | |Criterion 2 drops to 0 (Unsatisfactory) with quote None. Criterion 1 also fell from 2 to 1 in this single run, so the total went from 8 or 9 in the baseline runs to 4, not just by the 3 points of Criterion 2.
[7] Known failure modes and mitigation.
Two weaknesses were identified during testing:
First, borderline descriptions can shift between adjacent score tiers. In the English tests, Criterion 3 received 2 points in Runs 1 and 3, but 3 points in Run 2 because Run 2 credited the mention of thermal mass reduction and ventilation improvement as sufficient mechanisms.
Second, in Run 3 (grade-en-3.out.txt) the quote for Criterion 4 ends in an ellipsis (...). Exact string matching would fail on it, so the script above accepts the part before the ellipsis.
To get shorter quotes, you can add this line to the grading rules. A run with this line was not tested here. For criteria whose scores split, run the prompt several times and compare; a person sets the final total.
Quote only the phrase that supports each score, verbatim and without an ellipsis.