Training GRPO with an LLM Judge in Arena¶
This tutorial trains an LLM on a reward that mixes a programmatic check with an LLM judge. A judge is another LLM, called through its provider’s API, that reads each completion and scores it against criteria you specify. It suits rewards that are hard to code, like whether the working is clear, while a code check keeps the parts you can verify exactly.
We build on Training GRPO on GSM8K in Arena: the same GSM8K dataset, project, model and
GRPO settings. Read that one first if you have not registered the gsm8k dataset yet.
Here the reward is:
Correctness (weight 0.6):
1.0when the final number matches the GSM8K answer.Judge (weight 0.4): a score from 0 to 1 for how clear and sound the working is, from
gpt-4.1-mini.
At the end we swap the per-completion judge for RULER, where one judge call compares every completion in a GRPO group.
Prerequisites¶
agilerl-arenainstalled and logged in (see Training GRPO on GSM8K in Arena).The
gsm8kreasoning dataset registered and theGSM8K Tutorialproject created, as in that tutorial.An API key for the judge’s provider. This tutorial uses OpenAI; any OpenAI-compatible endpoint, or Anthropic, also works.
The example files are in docs/_static/examples/gsm8k-judge/: reward.py,
manifest.yaml and manifest_ruler.yaml.
Store the Judge’s API Key¶
The training job calls the judge, so it needs your provider key. Arena keeps it as an organization secret: the manifest names the secret, and Arena passes it to the job as an environment variable of that name. The key never goes in the manifest.
import os
client.set_secret(name="OPENAI_API_KEY", value=os.environ["OPENAI_API_KEY"])
# Prompts for the value without echoing it
arena secrets set OPENAI_API_KEY
# Or read it from a local environment variable
arena secrets set OPENAI_API_KEY --from-env OPENAI_API_KEY
Run arena secrets list to check it is there. Arena shows each secret’s name and when it
was last updated, never the value. You can also add and replace secrets in the web app: open
your account settings, then the Organization tab, and use the Organization secrets
card. The secret belongs to your organization, so one key serves every run in it. See
Organization Secrets for more.
The Reward File¶
A rubric file can export a plain reward_fn, as in the GSM8K tutorial, or an OpenEnv
Rubric. A judge needs the second form. The harness calls the rubric on every turn with a
TurnAction (the model’s reply as action.message) and a
TurnObservation (the dataset row’s question and
answer, among other fields).
reward.py
# Copyright 2026 AgileRL
# SPDX-License-Identifier: Apache-2.0
import re
from openenv.core.rubrics.base import Rubric
from openenv.core.rubrics.containers import WeightedSum
from agilerl.llm_envs.rubrics import LLMGroupJudgeRubric, LLMJudgeRubric
CRITERIA = """\
The reply solves the math word problem. Each step of the working follows from
the problem or the step before it, and a student could follow it. The reply
ends with one final number inside <answer></answer> tags, and that number
matches the reference answer. Penalise wrong arithmetic, skipped steps,
repetition and padding."""
def extract_gold_answer(answer: str) -> str | None:
"""Return the final numeric answer from a GSM8K answer (the value after ``####``)."""
match = re.search(r"####\s*(-?[\d,]+)", answer)
return match.group(1).replace(",", "").strip() if match else None
def extract_model_answer(completion: str) -> str | None:
"""Return the final number inside the model's last ``<answer>...</answer>`` block."""
blocks = re.findall(r"<answer>([\s\S]*?)</answer>", completion)
if not blocks:
return None
number = re.search(r"-?[\d,]+", blocks[-1])
return number.group(0).replace(",", "").strip() if number else None
class Correctness(Rubric):
"""1.0 when the number in ``<answer>`` matches the GSM8K gold answer."""
component_name = "correct"
def forward(self, action, observation) -> float:
gold = extract_gold_answer(str(observation.answer))
predicted = extract_model_answer(action.message)
if gold is None or predicted is None:
return 0.0
return 1.0 if predicted == gold else 0.0
class RUBRIC(WeightedSum):
"""Correct final answer, plus a judge's score for the working."""
def __init__(self, judge) -> None:
super().__init__(
[Correctness(), LLMJudgeRubric(judge, CRITERIA)],
weights=[0.6, 0.4],
)
class RULER(LLMGroupJudgeRubric):
"""One judge call ranks every completion in a GRPO group against the criteria."""
def __init__(self, judge) -> None:
super().__init__(judge, CRITERIA)
What each piece does:
Correctnessis a plainRubric. It parses the gold number after####inobservation.answerand the number inside the reply’s<answer>tags, and returns1.0when they match.component_name = "correct"names its metric.LLMJudgeRubrictakes the judge client and your criteria. It shows the judge the question and the reply, plus the row’s answer asREFERENCE ANSWER, and asks for{"score": <0 to 1>, "reason": "..."}. A reply it cannot read scores 0.RUBRICcombines them with OpenEnv’sWeightedSum. The weights must add up to 1.RUBRIC.__init__takes ajudgeargument. That is how the judge reaches the rubric: when the manifest has ajudgeblock, Arena builds the rubric class with the run’s shared judge client. A rubric that is built at import time, such as a module-level instance, cannot receive it, soRUBRICmust be a class.RULERis only used in the variant at the end. It is ignored until a manifest names it.
Write criteria the way you would brief a human grader: what a good reply does, and what to mark down. The judge also sees the reference answer, so the criteria can refer to it.
Note
The judge sees the reply without its reasoning block. Pass
LLMJudgeRubric(judge, CRITERIA, include_reasoning=True) to show it the reasoning
too. That trains the model to write reasoning the judge likes, so leave it off unless
that is what you want.
The Manifest¶
The manifest is the GSM8K one with three additions to environment:
manifest.yaml
---
algorithm:
name: GRPO
batch_size: 8
beta: 0.001
lr: 0.000005
clip_coef: 0.2
max_grad_norm: 0.1
update_epochs: 1
group_size: 8
temperature: 0.9
calc_position_embeddings: true
environment:
name: gsm8k
env_type: rollout
dataset: gsm8k
rubric_file_path: reward.py
rubric_name: RUBRIC
judge:
provider: openai
model: gpt-4.1-mini
api_key_env: OPENAI_API_KEY
max_tokens: 512
prompt_template:
system_0: >-
Solve the problem. Show your working step by step, then give the
final number inside <answer></answer> tags.
user_1: '{question}'
replay_buffer:
kind: llm
training:
max_steps: 100_000
evo_steps: 5
pop_size: 1
eval_loop: 1
evaluation_interval: 5
network:
pretrained_model_name_or_path: Qwen/Qwen3.5-0.8B
max_context_length: 1024
lora_config:
lora_r: 16
lora_alpha: 64
task_type: CAUSAL_LM
rubric_file_path: reward.pyis the reward file. It must have the same file name as the file you pass to--reward-file. You can leave it out and let--reward-filefill it in.rubric_name: RUBRICis the symbol to load from that file. Without it, Arena looks forreward_fn.judgedescribes the judge:provider:openai(the default),anthropicorbedrock.openaicovers any OpenAI-compatible endpoint.model: the judge’s model id.api_key_env: the name of the organization secret holding the key, never the key.max_tokens: the judge’s reply budget (default 4096). A judge that thinks before it answers spends this budget on its thinking too, so keep it high for thinking models or the verdict gets cut off. 512 is plenty forgpt-4.1-mini.
The judge block also takes base_url, max_concurrency (requests in flight per
process, default 16), timeout_s (seconds per attempt, default 120) and temperature
(default 0; Anthropic judges reject it). To use a judge hosted somewhere other than OpenAI,
set base_url. For example, through OpenRouter:
judge:
provider: openai
model: openai/gpt-4.1-mini
base_url: https://openrouter.ai/api/v1
api_key_env: OPENROUTER_API_KEY
max_tokens: 512
A URL with a path is used as given. A bare host, such as a self-hosted vLLM server at
http://judge:8000, gets /v1 added. Leave api_key_env out only when the endpoint
needs no key; without base_url it is required.
A bedrock judge calls Amazon Bedrock with the training machine’s own AWS credentials,
so it takes a region and no base_url or api_key_env. Organizations billed
through AWS Marketplace can use only Bedrock judges.
judge:
provider: bedrock
model: deepseek.v3.2
region: us-east-1
The prompt asks the model to show its working and put the final number in
<answer></answer> tags, which is what Correctness parses and the criteria check.
Note
On a dataset registered in Arena, Arena currently trains with the dataset’s default
prompt in place of prompt_template. That prompt also asks for <answer></answer>
tags, so this reward works either way. Check the prompt in the experiment’s Completions
view before relying on a custom one.
Tip
Validate the manifest before you submit. arena experiments submit validates it too,
but this is quicker while editing:
from agilerl.arena.models.manifest import TrainingManifest
TrainingManifest.get_validated("manifest.yaml")
Submit the Job¶
Submit the manifest with the reward file. The judge’s key is not passed here; the job reads it from the organization secret.
result = client.submit_experiment(
manifest="manifest.yaml",
reward_file="reward.py",
project="GSM8K Tutorial",
experiment_name="gsm8k-judge-v1",
)
arena experiments submit manifest.yaml \
--reward-file reward.py \
--project 'GSM8K Tutorial' \
--experiment-name gsm8k-judge-v1
Every completion now costs a judge call. With group_size: 8 that is eight calls per
prompt, so check your provider’s rate limits and spend before a long run.
max_concurrency caps how many calls each process has in flight. The provider SDK
retries rate limits, server errors and timeouts. A call that still fails is an episode
failure. Arena drops that group and keeps training. The run stops after 8 episode
failures in a row. The RULER variant below uses the same rule.
Watch the Judge¶
On top of the usual training metrics, a judge run logs:
Metric |
What it tells you |
|---|---|
|
The |
|
The judge’s score, before weighting. |
|
Judge calls since the last log. |
|
Share of judge replies with no readable score. Each one scores 0, so a high rate
is noise in your reward. Check |
|
Mean seconds per judge call. If it climbs, the judge is slowing training down: raise
|
The success and accuracy metrics count a completion as solved when its reward reaches
max_reward, which Arena sets to 1 for a reasoning dataset. With the weights here, only a
correct answer that the judge scores 1 reaches it, so read reward_correct for accuracy.
Download them as in the GSM8K tutorial:
arena experiments metrics gsm8k-judge-v1 --output-file metrics.csv --overwrite
To see why the judge scored a completion, open the experiment in the Arena web app and go
to its Completions view. For a run with a judge, each completion has a Judge notes
column: the judge’s one-sentence reason, labelled with the rubric component that wrote
it (judge here). When the judge’s reply could not be read, the note is the raw reply,
which usually shows what went wrong.
Read a sample of notes early in the run. If the judge rewards something you did not mean, such as long answers, tighten the criteria and resubmit. A judge that is easy to please trains a model to please it.
Variant: RULER¶
GRPO already compares the completions in a group: each one’s advantage is its reward minus the group mean. RULER gives the judge the same view. Instead of scoring each completion alone, one call shows the judge every completion in the group and asks for a score for each. Comparing replies side by side is often easier for a judge than giving each one an absolute score, and a group of eight needs one call instead of eight.
LLMGroupJudgeRubric implements it. reward.py already
defines RULER; it uses the same __init__(self, judge) pattern:
class RULER(LLMGroupJudgeRubric):
def __init__(self, judge) -> None:
super().__init__(judge, CRITERIA)
To use it, the manifest names it as group_rubric_name and points rubric_name at
Correctness alone, so the judge only runs once per group:
environment:
rubric_file_path: reward.py
rubric_name: Correctness
group_rubric_name: RULER
judge:
provider: openai
model: gpt-4.1-mini
api_key_env: OPENAI_API_KEY
max_tokens: 512
The full file is manifest_ruler.yaml. Submit it the same way:
arena experiments submit manifest_ruler.yaml \
--reward-file reward.py \
--project 'GSM8K Tutorial' \
--experiment-name gsm8k-ruler-v1
How it differs from the per-completion judge:
Each group score is added to that completion’s
Correctnessreward before the success check, so a completion can score up to 2. It is logged asreward_group_judge. Accuracy still uses Arena’smax_rewardof 1, so a completion counts whenCorrectnessplus the group score is at least 1: every correct answer, and a wrong answer the judge scores 1.Leave
rubric_nameout and the turn reward on dataset rows is 0, so the group score is the whole reward.The judge sees the completions in a new random order on every call, so a judge that favours one position adds noise rather than bias.
A reply it cannot read, or with the wrong number of scores, scores the whole group 0 and counts in
judge_parse_failure_rate.A judge call that still fails after the SDK’s retries fails that group’s episode tasks, which drops the group. The run stops after 8 episode failures in a row.
Raise
max_tokenswithgroup_size: the judge writes one reason per completion.Judge notes still appear per completion in the Completions view, labelled
group_judge(theLLMGroupJudgeRubriccomponent name).Held-out evaluation episodes get no group score.
See also
Arena Client for the full CLI and Python SDK reference, and the “An LLM judge” and “Scoring a group together (RULER)” sections of Environments (OpenEnv) for every rubric and judge option.