Skip to main content

Tutorial 4 — Semantic judging with llm-rubric

Goal: grade the agent's explanation of what it did, not just whether the code compiles. Use a judge model to score prose against a written rubric.

You will learn: the llm-rubric Check, how to write rubrics that don't false-positive, when to reach for llm-rubric vs exec, the not-any-of composite (the read-only contract), and the bypassPermissions mode for self-verifying agents.

Prerequisites: Tutorial 3 (you understand exec and permission modes). ANTHROPIC_API_KEY exported — the judge Model calls Anthropic too.

Cost: roughly $0.03 for the agent + ~$0.001 for the judge call, per run.

Why some answers can't be grep'd​

This Bench ships a testdata directory with this code:

// add.go (broken)
func Add(a, b int) int {
return a - b // should be: return a + b
}

go test ./... fails. The exec [go test ./...] Check is sufficient to grade the fix. But the prompt also asks the agent:

In your final message, briefly explain what the bug was.

How do you grade an explanation? contains "operator" is too permissive — the agent might say "I changed the operator from minus to minus" and pass. regex "subtraction.*addition" is too brittle — the agent might say "the function used - instead of +" and fail. What you actually want is: does the explanation correctly identify the bug as a sign-error or wrong-operator issue? That is a semantic question. It needs a judge.

llm-rubric is the answer. You write a rubric in plain English describing what a correct answer looks like; a judge Model reads Session.FinalOutput and your rubric, and emits {Pass, Score, Reason}. Score follows madbench's scoring contract: 0 to 1, higher is better. Raw or metric-native details belong in evidence, not in the primary score.

Step 0 — Create the project​

mkdir bugfix-add
cd bugfix-add

Layout you are about to build:

bugfix-add/
├── madbench.yaml
└── code/
├── go.mod
├── add.go # ships with `return a - b` (the bug)
└── add_test.go

Step 1 — Build the testdata​

Fast path — you can skip the inline files below and curl the prebuilt testdata from madbench-examples:

curl -sL https://github.com/MadAppGang/madbench-examples/tarball/main \
| tar -xz --strip-components=2 \
'MadAppGang-madbench-examples-*/04-semantic-judging/code'

The command drops a code/ directory with the testdata files into your current directory. Then jump to Step 2. The inline walkthrough below is for readers who want to see the testdata structure as they type.

mkdir -p code

code/go.mod

module example.com/bugfix-add

go 1.22

code/add.go

package add

// Add returns the sum of a and b.
func Add(a, b int) int {
return a - b
}

code/add_test.go

package add

import "testing"

func TestAdd(t *testing.T) {
cases := []struct{ a, b, want int }{
{3, 4, 7},
{10, 20, 30},
{-5, 5, 0},
{0, 0, 0},
{100, -50, 50},
}
for _, c := range cases {
if got := Add(c.a, c.b); got != c.want {
t.Errorf("Add(%d, %d) = %d, want %d", c.a, c.b, got, c.want)
}
}
}

Verify the red state:

cd code
go test ./...
# Expected: FAIL — the - vs + bug breaks every case
cd ../..

Step 2 — Write madbench.yaml​

In the project root (bugfix-add/):

description: "bugfix — agent fixes Add and explains the bug"
harness:
type: claude-code
model: claude-haiku-4-5-20251001
args: ["--permission-mode", "bypassPermissions"] # NEW vs Tutorial 3
defaults:
sandbox: home
timeout: 120s
capture: log

scenarios:
- name: fix-add-and-explain
testdata: ./code
prompt: |
In the Go module at the current working directory, the test in
add_test.go is failing. Find the bug in add.go, fix it, and verify
with 'go test ./...'.

In your final message, briefly explain what the bug was.
checks:
# Primary: tests pass
- type: exec
cmd: go test ./...
expected_exit: 0

# Anti-cheat: fix is canonical, not `return 7` or special-case input
- type: exec
cmd: grep -E 'return a \+ b|return b \+ a' add.go

# Session: agent used Edit (right tool for changing one line)
- type: session:tool-used
value: "Edit"

# Anti-cheat: original failing cases are still in the test file
- type: exec
cmd: grep -F '{3, 4, 7}' add_test.go
- type: exec
cmd: grep -F '{10, 20, 30}' add_test.go

# Semantic: did the agent correctly identify the bug?
- type: llm-rubric
value: |
The output explains that the bug was using subtraction (or '-')
in a function that should perform addition (or '+'). A correct
verdict mentions either:
- the wrong operator (- vs +), or
- that the function was subtracting instead of adding.
A "did the right thing" answer that doesn't name the bug should fail.

- type: latency
threshold: 90000
- type: cost
threshold: 0.10

bypassPermissions because the agent will run go test itself to verify its fix. The prompt explicitly says "verify with go test ./..." — without Bash permission the final message becomes "please approve go test" and the rubric will fail (the agent never wrote an explanation, just a permission request).

Permission mode is part of the Bench design, not infrastructure. Tutorial 3 used acceptEdits (harness verifies), this tutorial uses bypassPermissions (agent verifies). Both are valid; they grade different agent behaviors. An agent that self-verifies has a different session shape — and a different cost profile — than one that relies on the harness.

Step 3 — What makes the rubric good​

- type: llm-rubric
value: |
The output explains that the bug was using subtraction (or '-')
in a function that should perform addition (or '+'). A correct
verdict mentions either:
- the wrong operator (- vs +), or
- that the function was subtracting instead of adding.
A "did the right thing" answer that doesn't name the bug should fail.

Three things this rubric does well:

  1. Specifies what counts as correct. Two acceptable framings ("wrong operator" or "subtracting instead of adding"). The judge has clear positive criteria.
  2. Specifies what counts as wrong. The last line is the anti-pattern guard. Without it, "I fixed the bug and the tests pass now" passes the rubric. The agent did do the right thing — but it didn't name the bug, which was the assignment.
  3. Stays narrow. It does not grade prose quality, brevity, or whether the agent used backticks. It grades exactly one thing: did the explanation identify the operator error?

The judge sees Session.FinalOutput and the rubric. Nothing else. No testdata, no session, no Checks. If your rubric assumes the judge can see the test cases or the diff, you will get false-positives. Write rubrics that score on what is actually visible to a fresh reader of the final message.

Rubrics that don't say what fails are too easy. "The output explains the bug." is too loose — the agent can wave at "there was a problem in add.go" and pass. Always include the negative case: "An answer that doesn't name the bug should fail." Force the judge to reject the boundary case.

Step 4 — Why anti-cheat with exec greps still matters​

The grep Checks in step 2 catch what the rubric can't see: a judge model can be sympathetic. If the agent's explanation reads beautifully but the test is passing because the agent deleted the failing cases, the rubric still passes (the explanation is plausibly correct in isolation). The exec greps catch the diff-level cheat that the judge — which only sees FinalOutput — cannot.

Step 5 — Run it and read the judge's reasoning​

madbench --report-json out/bugfix.json

Now look at the judge's verdict:

jq '.results[0].checks[] | select(.type == "llm-rubric")' out/bugfix.json

You should see something like:

{
"type": "llm-rubric",
"pass": true,
"score": 1.0,
"reason": "The output names the bug as subtraction in place of addition: 'The Add function was using - instead of +'. Matches the rubric's first acceptable framing."
}

The reason field is your debugger when the rubric fails on what looks correct. A common failure: the agent's answer is correct but terse — "Fixed the operator." — and the rubric requires it to say "subtraction" or "addition". Either tighten the prompt ("explain explicitly which operator was wrong") or loosen the rubric.

Step 6 — When NOT to use llm-rubric​

QuestionRight Check
Does the test pass?exec
Is this exact string in the answer?contains
Did the agent use Edit?session:tool-used
Did the agent finish in under 60 seconds?latency
Is the agent's explanation of the bug correct?llm-rubric
Does the answer mention all three callers?contains-all (cheaper, no judge call)
Is the answer well-written, polite, and helpful?Don't grade this. It's a tarpit.

Reach for llm-rubric only when the cheaper Checks cannot answer the question. Every rubric call is another network round-trip and another ~$0.001. More importantly: every rubric is another judge whose verdicts you have to debug when a Bench flakes. Cheap Checks are deterministic. Rubrics are not.

Run the rubric against a deliberately-wrong final output before trusting it. If your rubric passes a hand-written "I fixed the bug." (no naming, no specifics), it is too loose. If it fails a hand-written "The bug was that Add subtracted instead of added.", it is too strict. Calibrate against both poles before shipping.

Judges drift across Model versions. When Anthropic ships a new Haiku, your rubric's interpretation may shift slightly. This is one more reason to keep rubrics narrow — narrow rubrics are less sensitive to judge variance.

Choosing a judge provider​

By default the judge is Anthropic: with ANTHROPIC_API_KEY exported, llm-rubric (and every other AI Check) is graded by claude-haiku-4-5. That is the zero-config path — no judges: block needed.

To use a different judge model, or several, declare a bench-level judges: block. Every provider value is a model spec in one of two notations:

Short notation — a single string. Either a bare model whose provider is inferred from its prefix, or an explicit provider/model. The built-in provider table supplies the endpoint, the conventional API-key env var, and (if you name only the provider) a default model:

judges:
default: opus-4.8 # inferred → anthropic, ANTHROPIC_API_KEY
providers:
fast: haiku-4.5 # anthropic; canonicalized to claude-haiku-4-5
ds: deepseek/deepseek-chat # explicit provider/model
flash: gemini-2.5-flash-lite

Long notation — a map, for gateways not in the table (OpenRouter, Together, a local vLLM/Ollama) or to attach sampling params:. transport/endpoint are the canonical keys; type/base_url are accepted as aliases (older configs keep working):

judges:
default: or-qwen # optional; defaults to the sole/first provider
providers:
or-qwen:
transport: openai # OpenAI-compatible chat-completions API
endpoint: "https://openrouter.ai/api/v1"
model: "qwen/qwen3-235b"
api_key_env: OPENROUTER_API_KEY
params: # optional provider-level sampling defaults
temperature: 0.0
max_tokens: 1024
claude:
type: anthropic # `type:`/`base_url:` still accepted as aliases
model: "claude-haiku-4-5"
api_key_env: ANTHROPIC_API_KEY

The API key value never appears in YAML — api_key_env names an environment variable read at run start. A provider whose api_key_env is unset is skipped (same silent-skip as the default env path). Naming a missing provider as the explicit default: is a config error surfaced at run start.

Built-in providers (short notation infers these; the endpoint/env come free):

Provider (aliases)API-key envDefault modelEndpoint
anthropic (claude)ANTHROPIC_API_KEYclaude-haiku-4-5api.anthropic.com
openai (gpt)OPENAI_API_KEYgpt-4.1-nanoapi.openai.com/v1
gemini (google)GEMINI_API_KEYgemini-2.5-flash-litegenerativelanguage.googleapis.com/v1beta/openai
grok (xai)XAI_API_KEYgrok-4.1-fastapi.x.ai/v1
glm (zai, zhipu)ZAI_API_KEYglm-4.6-flashapi.z.ai/api/paas/v4
minimaxMINIMAX_API_KEYMiniMax-M2.5api.minimax.io/v1
kimi (moonshot)MOONSHOT_API_KEYkimi-k2.5api.moonshot.ai/v1
deepseekDEEPSEEK_API_KEYdeepseek-v4-flashapi.deepseek.com
mistralMISTRAL_API_KEYmistral-small-latestapi.mistral.ai/v1
qwen (dashscope, alibaba)DASHSCOPE_API_KEYqwen-flashdashscope-intl.aliyuncs.com/compatible-mode/v1
openrouterOPENROUTER_API_KEYopenrouter/autoopenrouter.ai/api/v1
ollama (ollama-cloud)OLLAMA_API_KEYgpt-oss:20b-cloudollama.com/v1

Every provider except anthropic speaks the OpenAI-compatible transport. Endpoints are the international variants — swap for the China-mainland hosts (bigmodel.cn, dashscope.aliyuncs.com, minimaxi.com, moonshot.cn) if you operate there.

The last two are gateways: they host other vendors' catalogs, so they have no model-prefix inference — reach them explicitly (openrouter/anthropic/claude-sonnet-5, ollama/qwen3-coder:480b-cloud; everything after the first / is the literal model id, slashes and :tags included). A bare provider key is also a valid short form resolving to that provider's default model — default: openrouter gives you the auto-router, default: ollama the cheapest hosted model. Local (non-cloud) Ollama: use long form with endpoint: http://localhost:11434/v1.

A specific Check can pick a judge with judge, override the model with model, and override sampling with temperature / max_tokens; each unset falls back to the bench default and then the provider default:

- type: llm-rubric
value: |
A correct answer identifies the bug as a wrong-operator / sign error.
An answer that doesn't name the bug should fail.
judge: claude # optional; else the bench default judge
model: claude-opus-4-8 # optional per-check model override
temperature: 0.0 # optional per-check sampling override
max_tokens: 512

Step 7 — not-any-of for read-only contracts​

A common need that didn't fit this Bench but is worth seeing now: the read-only contract. When you have a Q&A Bench (like Tutorial 2's codenav) and want to guarantee the agent didn't mutate the codebase, you combine default permission mode with an explicit not-any-of Check:

# READ-ONLY contract: the agent must NOT have used any of these tools
- type: not-any-of
checks:
- type: session:tool-used
value: "Write"
- type: session:tool-used
value: "Edit"
- type: session:tool-used
value: "MultiEdit"

not-any-of passes when none of its children pass — i.e. when the agent did not use Write, Edit, or MultiEdit. Combined with default permission mode, the agent literally cannot break the contract even if it tried — but the Check makes the contract explicit in the YAML so a future reader knows "this is a read-only Bench by design."

This is the same shape pattern you saw in Tutorial 2's any-of, inverted:

  • any-of = "at least one child passes" (1 of N)
  • not-any-of = "no child passes" (0 of N)
  • assert-set (Tutorial 1) = "at least K of N" (the general case)

The other way round: session:tools-only​

The Check above is a denylist — it names what must not happen. That is exactly right when the forbidden list is short and stable, as it is here: Write, Edit, MultiEdit.

When you can instead name what the run may do, write the allowlist and let one Check carry the whole fence:

# READ-ONLY contract, stated as what IS allowed
- type: session:tools-only
value: ["Read", "Grep", "Glob", "Bash"]

Each entry may be a matcher, so glob:mcp__serena__* fences a whole MCP server in one line rather than one line per tool. The rule for choosing:

  • Allowlist (session:tools-only) when you can enumerate the permitted surface — a read-only contract, an MCP-free control run, a subagent's tools: fence. It cannot fall behind a tool surface that grows.
  • Denylist (not-any-of over session:tool-used) when you can only enumerate the forbidden ones, inside an otherwise open surface.

A failure names the first call outside the fence and its position (Write is not allowed (call 7 of 19); allowed: [Read Grep Glob Bash]), and the Evidence lists every violation. Full semantics: ../checks.md.

Step 8 — Read the full JSON report​

# Final answer — the prose the rubric graded
jq -r '.results[0].session.finalOutput' out/bugfix.json

# Session — Edit + Bash (go test) + final message
jq '.results[0].session.calls[] | {tool: .name}' out/bugfix.json

# All check verdicts side by side
jq '.results[0].checks[] | {type, pass, score, reason}' out/bugfix.json

You should see exactly one Edit (the operator fix), one or more Bash calls (the agent verifying with go test), and the final assistant message. The cost line will be ~$0.03 — slightly more than Tutorial 3's fizzbuzz because the agent did Read + Edit + Bash + final-write, vs. Read + Write.

What you now know​

ConceptWhy it matters
llm-rubricSemantic grading via a judge Model
Rubric design (positive + negative criteria)Avoids both false-positive and false-negative
bypassPermissionsAgent self-verifies with Bash (go test)
not-any-of"None of these tools were used" — the read-only contract
Anti-cheat layered with rubricThe judge can't see what grep can; stack both
When NOT to use rubricIf exec / contains / session can answer it, use those

What you do not yet know​

Every Bench so far has been one Scenario, one testdata directory. SWE-bench evaluates an agent against hundreds of distinct problems and reports pass@1 across them all. Tutorial 5 introduces the parameterized multi-Scenario Bench — a scenarios: array with N entries, each with its own testdata: path — plus the --trials N flag for running N trials and the TrialsReport JSON schema for aggregating pass@1.


Previous: Tutorial 3 — codegen with exec Checks Next: Tutorial 5 — SWE-bench-style multi-Scenario Benches