Skip to main content

Gandalf the Grader Build Status Coverage PyPI PyPI - Python version

Your verifier is probably the bottleneck. We built one that isn't.

Gandalf vs. baseline verifiers on BankerVerifierBench (cost vs. F1)

Read the launch blog post for the motivation, benchmark results, and design rationale behind Gandalf.

Gandalf is a reactive agent-as-judge for rubric-graded agent environments. Given a rubric of binary criteria, it runs inside the rollout environment, uses the same tools as the rollout agent, and decides at inference time which files to open and which tool state to query.

That lets Gandalf grade criteria that depend on artifacts or state — formulas in a workbook, charts in a deck, files on disk, MCP tool state, or whether an email was actually sent — rather than just the final text response.

Gandalf is built around three design choices:

  • Environment alignment: Gandalf runs in the same filesystem, Python interpreter, installed packages, and tool environment as the rollout agent, using the OpenHands SDK as the agent harness.

  • Reactive verification: Gandalf chooses what evidence to inspect while grading, instead of relying on a precomputed transcript or serialized snapshot.

  • Swappable domain guidance: Domain knowledge enters as natural-language guidance at runtime, making the same verifier portable across domains.

In our evaluation, this design beat text-only, snapshot-based, and workflow-based agentic verifiers at a fraction of the cost — see the blog post for the full meta-eval.

Examples and integrations: BankerToolBench is a public agentic RL benchmark environment that uses Gandalf as the verifier. rle-pkg is a reference runtime that integrates Gandalf. Both run under the Harbor framework, but Gandalf's design and implementation are framework-agnostic.

Installation

Gandalf is published on PyPI.

uv tool install gandalf-the-grader

For production use, we recommend that you pin a specific version of Gandalf, and furthermore use the [pinned] version to pin all transitive dependencies.

uv tool install 'gandalf-the-grader[pinned]==1.0.0'

Runtime dependencies

Important: Gandalf is built on top of OpenHands, which works best when tmux is installed. The judge refuses to run when tmux is not on PATH rather than silently falling back to a less stable subprocess-based terminal.

Quick start

The repo ships a runnable example under examples/quickstart/ that grades a pre-staged workspace + ATIF trajectory against a 3-criterion rubric. Two criteria are designed to be met and one is designed to fail, so you can see Gandalf's partial-credit grading and per-criterion reasoning in one run. From a fresh clone:

# 1. Install
uv tool install gandalf-the-grader

# 2. Provide a Gemini API key (any litellm-compatible model works; see Configuration)
export LLM_API_KEY="<your-gemini-api-key>"

# 3. Run from the repo root
gandalf-the-grader --config examples/quickstart/grader.toml

# 4. Inspect the result
cat examples/quickstart/output/reward.json   # -> {"reward": 0.75}
cat examples/quickstart/output/info.json     # per-criterion verdicts + reasoning

Expected verdicts: the welcome.txt file exists (met), the message mentions Gandalf (met), and the message is not longer than 50 words (unmet, by design). Raw score 3.0 of a possible 4.0, for a reward of 0.75.

The example uses gemini/gemini-2.5-flash and runs the inner judge as the current user (no sandbox_user, no sudo). To adapt it to your own setup, edit examples/quickstart/grader.toml. See the Configuration section below for the full field reference.

Configuration

grader.toml

Field Required Default Description
instructions Yes* Inline task instructions given to the original agent (mutually exclusive with instructions_path)
instructions_path Yes* Path to a file with task instructions (mutually exclusive with instructions)
rubric Yes* Inline rubric as a TOML array of tables (mutually exclusive with rubric_path)
rubric_path Yes* Path to rubric JSON file (mutually exclusive with rubric)
judge_guidance No Inline judge guidance text (mutually exclusive with judge_guidance_path)
judge_guidance_path No Path to a file with extra judge instructions (mutually exclusive with judge_guidance)
workdir Yes Agent workspace directory
trajectory_path Yes Path to ATIF trajectory JSON
output_dir Yes Directory for grader output files
model No gemini/gemini-2.5-flash LLM model for the judge agent
mode No batch Evaluation mode: batch or individual
judge_timeout No 300 Max seconds per judge invocation
batch_timeout No Max total seconds for batch mode (caps judge_timeout * N)
judge_retries No 1 Number of retry attempts for criteria that error due to infrastructure failures
batch_splits No Split criteria into N chunks in batch mode (>= 2). Each chunk is evaluated as a separate batch session. Only valid with mode = "batch".
max_concurrency No Max parallel judge sessions (>= 1). Defaults to 1 for individual mode, batch_splits for batch mode.
sandbox_user No Username for running the inner judge (via sudo). When omitted the judge runs as the current user.
judge_prompt No Inline Jinja2 template that completely overrides the built-in judge task prompt (mutually exclusive with judge_prompt_path)
judge_prompt_path No Path to a Jinja2 template file that completely overrides the built-in judge task prompt (mutually exclusive with judge_prompt)

MCP servers can be configured as TOML array of tables:

[[mcp_servers]]
name = "magic-server"
transport = "stdio"
command = "/usr/bin/mcp-server"
args = ["--verbose"]

Custom Judge Prompt

By default, the grader uses a built-in prompt template to kick off each judge session. judge_prompt / judge_prompt_path let you replace it entirely with a custom Jinja2 template.

Note: This prompt is sent as the opening user message to the judge agent, not the LLM system prompt. The underlying agent framework (OpenHands) has its own immutable system message with coding and tool-use instructions that we never modify. Our prompt sits on top of that as the first user turn, setting up the grading task.

For most use cases, judge_guidance / judge_guidance_path is all you need: it injects extra instructions into the built-in prompt without replacing it. Fully overriding the judge prompt is an uncommon escape hatch for situations where the built-in prompt structure itself is unsuitable.

The template receives these variables:

Variable Type Mode Description
instructions str both Task instructions given to the original agent
final_output str both Agent's final message from the trajectory
criterion str individual The single criterion string to evaluate
criteria list[str] batch List of all criterion strings to evaluate
verdict_path str both File path the judge must write its verdict to
judge_guidance str both Additional guidance text (may be empty)

Individual and batch modes use separate built-in templates. In a custom template, use {% if criterion is defined %} vs {% if criteria is defined %} if you need to distinguish modes. In batch mode, use loop.index0 for the criterion index (e.g., {% for c in criteria %}[{{ loop.index0 }}] {{ c }}{% endfor %}).

Rubric JSON

A JSON array of objects with criterion (string) and weight (float). Weights can be negative to penalise undesired outcomes:

[
  {"criterion": "The output file exists", "weight": 2.0},
  {"criterion": "The output contains correct totals", "weight": 3.0},
  {"criterion": "The agent used hardcoded values instead of computing", "weight": -1.0}
]
  • Positive weight: adds to the raw score when the criterion's condition is met
  • Negative weight: deducts from the raw score when the criterion's condition is met (the bad thing happened)
  • The judge evaluates each criterion on its own merits; it never sees weights

Trajectory Format (ATIF)

The grader reads agent trajectories in Agent Trajectory Interchange Format (ATIF). An ATIF file is a JSON object with a steps array:

{
  "steps": [
    {"source": "user", "message": "Build a hello world web app"},
    {"source": "agent", "message": "I'll create the file now", "tool_calls": [...]},
    {"source": "agent", "message": "Done! I created index.html with a Hello World page."}
  ]
}

The grader extracts the final agent message (last "source": "agent" step with a non-empty message and no tool_calls) and passes it to the judge as context.

Environment Variables

Variable Description
LLM_API_KEY API key for the LLM provider
LLM_BASE_URL Base URL for the LLM API (optional)
GRADER_INSTRUCTIONS_PATH Fallback path to task instructions file (if not set in TOML)
GRADER_JUDGE_GUIDANCE_PATH Fallback path to judge guidance file (if not set in TOML)
GRADER_JUDGE_PROMPT_PATH Fallback path to custom judge prompt template (if not set in TOML)
OTEL_EXPORTER_OTLP_ENDPOINT OTLP endpoint URL for trace export (optional)
OTEL_EXPORTER_OTLP_HEADERS OTLP auth headers, URL-encoded (optional)
OTEL_EXPORTER_OTLP_TRACES_PROTOCOL OTLP transport protocol, e.g. http/protobuf (optional)

Tracing / Observability

Gandalf builds on top of OpenHands, which has built-in OpenTelemetry tracing that automatically instruments LLM calls, tool executions, and agent steps. Set the OTEL_EXPORTER_OTLP_* variables above to export traces to any OTEL-compatible backend with no code changes required.

Example: Langfuse

# Encode your Langfuse keys
echo -n "pk-lf-...:sk-lf-..." | base64

# Export the variables
export OTEL_EXPORTER_OTLP_ENDPOINT=https://cloud.langfuse.com/api/public/otel/v1/traces
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Basic%20<base64-encoded-keys>"
export OTEL_EXPORTER_OTLP_TRACES_PROTOCOL=http/protobuf

Output

The grader writes to output_dir:

  • reward.json: Reward file (e.g., {"reward": 0.75}) (always in [0, 1]). Only written when all criteria are successfully evaluated. If any criteria still have errors after retries, the grader writes info.json but skips reward.json and exits with code 1.
  • info.json: Always written. Per-criterion results with met/not-met, reasoning, evidence, LLM usage, plus reward, raw_score, minimum_score, maximum_score, errored_criterion_count, and evaluated_criteria_pct.
  • judge_trace_*.txt: stdout/stderr capture for each judge invocation. Naming varies by mode: judge_trace_{i}.txt (individual), judge_trace_batch.txt (batch), judge_trace_batch_split{i}.txt (batch with splits). Retries append a _retry{N} suffix.

The reward in reward.json is clip(0, 1, raw_score / sum_of_positive_weights), always in [0, 1]. info.json additionally includes raw_score (the raw sum of weights for met criteria, which can be negative) and minimum_score/maximum_score bounds for reference.

Next steps

License

Copyright (c) Handshake. Released under the Apache-2.0 license. See LICENSE.txt for details.

Metadata

Release files for gandalf-the-grader 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gandalf-the-grader 1.0.2
File Size Uploaded
gandalf_the_grader-1.0.2.tar.gz 337.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gandalf-the-grader 1.0.2
File Interpreter ABI Platform
gandalf_the_grader-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 373.2 kB

Release files / gandalf_the_grader-1.0.2.tar.gz

Download URL gandalf_the_grader-1.0.2.tar.gz
Size 337.6 kB
Tags Source
SHA-256 checksum
How to use checksums
c580e25e8fc8e3c7bd46c0b10787e922210a62a53d62bb662d7a2953afdb3f62
BLAKE2b-256 checksum
How to use checksums
fad2fa1acd54639492f5071dea8b69239f282028f823b35bbffb707960fe04f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 18, 2026.

Transparency log

Release files / gandalf_the_grader-1.0.2-py3-none-any.whl

Download URL gandalf_the_grader-1.0.2-py3-none-any.whl
Size 35.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
57af90514b022f128c4a347347d19016cedc594f06a89f3cbecd734dc59b119e
BLAKE2b-256 checksum
How to use checksums
613288a5058229f75c94d160b7886c948586270b67ae3f23bfb8361b24a0f704
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 18, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.5.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page