Rubrics

Score model outputs with Python checks, built-in validators, or an LLM judge.

A Rubric combines one or more weighted checks (a Judge, a Scorer or a built-in validator) into an overall score, the weighted mean of its items, and keeps each check's score by name. You can use it in three places:

  • Evals: pass it as rubric= to client.evals.create to score each model's answers on a dataset. A single Judge, Scorer, validator or plain function works too.
  • Cleaning datasets: score old logs once with dataset.score(rubric), then filter on the scores.
  • Router training: pass a Judge or a Rubric of judges and validators as rubric= to RouterRecipe, or the name of a score already on your records (rubric="task_success").

Building a Rubric#

Mix fast code checks (validators, exact matches, length checks) with a Judge so obvious errors are caught cheaply and the judge only grades nuance:

Python
from grad import Judge, Rubric, Scorer, validators

rubric = Rubric([
    Scorer("valid_json", weight=0.3, fn=validators.JSON()),
    Judge(
        name="accurate_extraction",
        model="anthropic/claude-sonnet-5-5",
        prompt="Does the JSON capture every field the user asked for, without invented values?",
        weight=0.7,
    ),
])

Types of scorers#

Pick the class that matches how you grade an answer:

ClassSignatureWhen to use it
ScorerScorer(name, fn=..., weight=1.0)A built-in validator (fn=validators.JSON()), which runs on the server, or your own Python function fn(traj) -> float, which runs in your process. Return a score in [0, 1] (a bool counts as 1.0/0.0).
JudgeJudge(model, prompt=..., name="judge")Grade with a model id, such as "anthropic/claude-sonnet-5-5". The judge sees the conversation, the answer and any reference answer, and replies with a score in [0, 1]. model is required, with no default that could change under you. It must be a priced model: a catalog model, a judge model the server lists with a price, or an artifact in your workspace (see Judge and comparison models).
StatefulScorer(traj: Trajectory, handle: H) -> floatChecks live state inside an Environment, which is coming soon.

The built-in validators run on the server and score the trimmed output 1.0 or 0.0:

  • validators.JSON(): the output parses as JSON.
  • validators.NonEmpty(): the output isn't empty.
  • validators.ExactMatch(): the output equals the record's expected_output, or its final assistant turn when it has no expected_output.
  • validators.Regex(pattern, flags=""): the pattern matches the output. Patterns use JavaScript syntax, up to 256 characters, with flags from imsu.

Put one in a Rubric directly (Rubric([validators.JSON()])) or call it locally to test it: validators.JSON()('{"ok": true}') returns 1.0.

Two more server-side validators check answers against expected_output, and benchmark datasets use them by default:

  • final_number: the last number in the output equals the expected number.
  • choice: the chosen option letter matches the expected one.

They have no Python class yet: name them in a CLI rubric file (kind: validator, validator: final_number), or pass the wire item to an eval, rubric=[{"name": "answer", "kind": "validator", "validator": "final_number"}]. Write any other check, such as SQL parsing, TypeScript compilation or JSON Schema, as a Scorer.

Scoring a Dataset with a Judge#

dataset.score(judge) grades the answers already in your logs on the server and saves the results to trajectory.scores in the dataset's next version. Records that already have every score are skipped, so you can change filter thresholds or reuse scores across recipes without paying again:

Python
from grad import Grad, Judge

client = Grad()
dataset = client.datasets.get("support-prod")

judge = Judge(
    name="resolved",
    model="anthropic/claude-sonnet-5-5",
    prompt="Did the assistant resolve the user's request accurately without policy errors?",
)
scored = dataset.score(judge).wait()
good = scored.filter(scores={"resolved": ">=0.8"})

To grade a model's new answers on a dataset instead, run an eval with the same judge: client.evals.create(models=["qwen/qwen3-8b"], dataset="support-prod", rubric=judge).

Where Python scorers run#

Built-in validators and every Judge run on Gradiated's servers. Your own functions run in your own process (the Python, TypeScript and Go SDKs all do this) (runtime="local", the default). The eval waits in awaiting_scores while ev.wait() pulls the model outputs, calls your function and posts the scores, so keep the process running until the eval completes. If no SDK posts scores for 24 hours, the eval fails with an error naming the missing scorers. traj.text is the answer; traj.metadata and traj.expected_output come from the record:

Python
from grad import Scorer

def math_answer(traj) -> float:
    import sympy
    expected = sympy.sympify(traj.metadata["answer"])
    got = sympy.sympify(traj.text.strip())
    return 1.0 if sympy.simplify(got - expected) == 0 else 0.0

answer_check = Scorer("answer", fn=math_answer, requirements=["sympy==1.14.0"])

Before any model is called, evals.create checks that the declared requirements are installed and runs each function once on a sample record, so a broken scorer fails before you spend anything.

Python scorers in training recipes (RouterRecipe(rubric=Scorer(...))) run in a managed sandbox, which is coming soon; today the recipe rejects them. Compute the score yourself, store it in each record's scores, and pass its name instead. See Where your code runs.

Grading live state inside an Environment#

StatefulScorer(name, fn=f(traj, handle)) checks what an agent actually changed, such as a row inserted in Postgres or a test suite passing in a container. It runs inside an Environment rubric, which is coming soon; eval and training rubrics can't carry one.