Skip to content
AgenticAIWiki
  1. Learn
  2. Part 3
  3. 18. Graders: code, model and human
  4. 18.5

Lesson 18.5 · 5 of 5 · 4 min read · Reviewed 24 Nov 2026

Worked example: building a grader in the Playground

By the end, you can

  • Build a model grader with Claude.
  • Return structured verdicts you can aggregate.

A structured grader

Use a tool definition (or structured outputsStructured outputs: Making a model return data that matches a defined schema, such as JSON with required fields and types.) so the verdict always has the same shape:

grade_tool = {
  "name": "record_grade",
  "description": "Record the grade for one criterion.",
  "input_schema": {
    "type": "object",
    "properties": {
      "reasoning": {"type": "string"},
      "verdict": {"type": "string", "enum": ["pass", "partial", "fail"]}
    },
    "required": ["reasoning", "verdict"]
  }
}
# call the Messages API with tools=[grade_tool],
# tool_choice={"type": "tool", "name": "record_grade"}

Forcing the tool means every reply is a parseable grade (chapter 14).

Pin the grader

Version the grader like the product (72.1): model idModel id: The exact string that names a model in an API request, such as a specific model version., prompt version, effort. Record them with each score. When you change the graderGrader: The part of an eval that decides whether an output passes, using code, a model or a person., rescore a baseline so old and new scores can be compared.

Aggregate

criterion          pass   partial   fail
policy accuracy     88%      7%      5%
asks for info       94%      0%      6%
tone                81%     15%      4%

Try it here

The Playground simulates Claude calls in your browser, so you can design the grader prompt, the tool schema and the aggregation code without a real key. Real scores need a real model, which you’d run in your own project.

Key points

  • Use Claude as a grader with a rubric prompt and structured output so every verdict parses.
  • Keep grader settings fixed (model id, prompt version, effort level) so scores are comparable over time.
  • Practise in the Playground's simulated calls first; no real key or spend is needed to design the flow.
Hands-on labRuns in the Playground

Build a strict-tool grader in the Playground

Call the simulated Messages API with a strict record_grade tool so every verdict comes back in a fixed shape.

You will have: A grading script that pins the grader version, validates each verdict and prints an aggregate table.

Steps

  1. Read the grade_tool schema: reasoning plus a verdict from pass, partial or fail.
  2. Call client.messages.create with tools=[grade_tool], tool_choice on auto, and a prompt that asks for record_grade.
  3. Pull the tool_use block out of the reply and check the verdict is one of the allowed values.
  4. Record the grader version with each result and print the totals.

Done when

  • Each of the 3 replies produces one tool_use block.
  • Every result row carries the grader version g1.
  • Verdicts outside the enum are counted as invalid, not silently kept.

Open in the Playground No API key needed.

Starter code (Python)
import anthropic

client = anthropic.Anthropic()  # simulated: no real key or network is used
GRADER = {"version": "g1", "model": "claude-sonnet-5-5", "rubric": "policy-accuracy-v3"}
grade_tool = {
    "name": "record_grade",
    "description": "Record the grade for one criterion. Always call this to give your verdict.",
    "strict": True,
    "input_schema": {
        "type": "object",
        "properties": {
            "reasoning": {"type": "string"},
            "verdict": {"type": "string", "enum": ["pass", "partial", "fail"]},
        },
        "required": ["reasoning", "verdict"],
    },
}
REPLIES = [
    "Sale items are final sale unless faulty.",
    "You have 60 days to return anything.",
    "Unworn footwear can be returned within 30 days.",
]

rows = []
for reply in REPLIES:
    # TODO: call client.messages.create(model=GRADER["model"], max_tokens=300, tools=[grade_tool],
    # TODO:     tool_choice={"type": "auto"},  # newest models reject forced tool use messages=[...]) with the policy and reply
    # TODO: find the tool_use block and read block.input["verdict"]
    verdict = "invalid"
    rows.append({"reply": reply[:30], "verdict": verdict, "grader": GRADER["version"]})

for r in rows:
    print(r)
print("graded", len(rows), "replies")
Show a solution
import anthropic

client = anthropic.Anthropic()  # simulated: no real key or network is used
GRADER = {"version": "g1", "model": "claude-sonnet-5-5", "rubric": "policy-accuracy-v3"}
POLICY = "Footwear may be returned within 30 days if unworn. Sale items are final sale unless faulty."
ALLOWED = {"pass", "partial", "fail"}
grade_tool = {
    "name": "record_grade",
    "description": "Record the grade for one criterion. Always call this to give your verdict.",
    "strict": True,
    "input_schema": {
        "type": "object",
        "properties": {
            "reasoning": {"type": "string"},
            "verdict": {"type": "string", "enum": ["pass", "partial", "fail"]},
        },
        "required": ["reasoning", "verdict"],
    },
}
REPLIES = [
    "Sale items are final sale unless faulty.",
    "You have 60 days to return anything.",
    "Unworn footwear can be returned within 30 days.",
]

rows, tool_calls = [], 0
for reply in REPLIES:
    msg = client.messages.create(
        model=GRADER["model"],
        max_tokens=300,
        tools=[grade_tool],
        tool_choice={"type": "auto"},  # newest models reject forced tool use
        messages=[{"role": "user", "content": f"Grade policy accuracy. Call record_grade with your verdict.\n<policy>{POLICY}</policy>\n<reply>{reply}</reply>"}],
    )
    blocks = [b for b in msg.content if b.type == "tool_use"]
    tool_calls += len(blocks)
    verdict = "invalid"
    if blocks:
        v = str(blocks[0].input.get("verdict", "")).lower()
        verdict = v if v in ALLOWED else "invalid"
    rows.append({"reply": reply[:30], "verdict": verdict, "grader": GRADER["version"]})

for r in rows:
    print(r)
counts = {v: sum(r["verdict"] == v for r in rows) for v in ["pass", "partial", "fail", "invalid"]}
print("totals:", counts)
print("tool_use blocks:", tool_calls, "of", len(REPLIES))
print("grader version:", GRADER["version"], "| graded", len(rows), "replies")

Do it Practise structured output in the Playground in the Playground. No API key needed.

Quick checkYou change the grader's prompt and scores rise 5 points. What can you conclude about the product?
How sure are you?
Pick an answer and how sure you are

Finished the chapter? Take the chapter check.