Learn › Testing & Evaluating AI Agents and RAG › Graders: Code, Model, and Human

Graders: Code, Model, and Human

Intermediate 🕐 16 min Lesson 4 of 11
What you'll learn
  • Describe code-based, model-based, and human graders and their trade-offs
  • Match grader types to different criteria
  • Combine several graders on one task
  • Explain the deterministic-first rule
  • Recognize when a failing grade points to a broken grader

What a Grader Does

Anthropic defines a grader as "logic that scores some aspect of the agent's performance." One task can have several graders, and each grader can contain several checks. Choosing the right grader type for each criterion is the core design decision in any eval.

Code-Based Graders

These are ordinary programs: string matching, binary tests, static analysis, and checks on tool calls or on the state of a database. Anthropic lists their strengths as fast, cheap, objective, reproducible, and easy to debug. The weaknesses are brittleness to valid variations and a lack of nuance for subjective work. Typical examples:

  • Exact match after normalizing whitespace and case, as in a labeled sentiment eval
  • A required phrase or fact appears in the output
  • The output parses as valid JSON or matches a schema
  • A particular tool was, or was not, called, with the right arguments
  • A database row or file exists after the run
  • Unit tests or a linter pass on generated code
def grade_refund(result, db):
    created = db.refund_exists(result.order_id)
    within_limit = result.refund_amount <= 100
    return created and within_limit

Notice that this grader checks the database, not the agent's wording.

OpenAI's evaluation guide also lists metric-based methods such as exact match, string match, function-call accuracy, and executable checks like running generated SQL. It notes that overlap metrics such as ROUGE and BLEU can miss nuance, so use them for regression checks, not as proof of quality.

Model-Based Graders

A model grader asks an LLM to score an output against a rubric, compare two answers, check natural-language assertions, or compare against a reference. Anthropic describes them as flexible, scalable, and good with open-ended output. The costs: they are non-deterministic, more expensive, and need calibration against human judgment. The next lesson covers how to do that.

Human Graders

Expert review, crowdsourcing, spot checks, A/B tests, and inter-annotator agreement produce the gold standard and are how you calibrate model graders. They are also slow and expensive and require experts at scale. OpenAI's guidance recommends pairing a score with a pass/fail threshold and using consensus voting across reviewers.

A Worked Example: Support Agent

Anthropic sketches a conversational support eval that it labels theoretical. A customer asks for a refund, and several graders run on the same trial:

  • Model rubric — is the reply empathetic, clear, and grounded in tool results?
  • State check — is the ticket resolved and the refund processed?
  • Tool-call constraint — was the refund amount within the allowed limit?
  • Turn limit — finished in no more than 10 turns

The guide notes that conversational evals often use a second LLM to simulate the customer. Each grader covers what it is best at, and no single one has to be perfect.

How to Combine Them

Anthropic's recommendation is to use deterministic graders wherever possible, LLM graders where flexibility is needed, and human graders sparingly. Scores can be weighted (a threshold on a combined score), binary (every check must pass), or hybrid. Choose per task: a safety check should be binary, while a tone check can be one weighted input. Additional design rules from the same guide:

  • Grade each dimension with its own isolated judge instead of one judge for everything
  • Give model graders an "Unknown" option so they do not guess
  • Make graders hard to game: check the real outcome, not a phrase the agent can simply say
  • Build in partial credit for tasks with several components

Avoid Brittle Checks

Rigid graders can punish correct answers. Anthropic describes a case where a grader rejected "96.12" because it expected "96.124991…", and fixing the grading, along with other scaffold issues, raised one model's score from 42% to 95%. When a good answer fails, suspect the grader before the system.

Try This

Take five tasks from your test set. For each criterion, label the best grader type and write one sentence explaining why. Then write the code-based graders first, run them, and read every failure. You will often find that code graders cover more than you expected, and the failures will show you which model graders you truly need.

Key takeaways
  • Use code graders wherever the criterion is objective
  • Model graders add flexibility but need calibration
  • Humans are the gold standard and the calibration source, used sparingly
  • Grade outcomes and state, not only wording
  • A failing grade can be a grader bug
Learn more every week Get 5 hand-picked prompts + new AI tools every Monday. Free.