Skip to main content

Overview

JudgeRubric extends Rubric to provide LLM-as-judge scoring. It uses a language model to evaluate whether responses are correct by comparing them against ground truth answers.

Constructor

Parser | None
default:"None"
Parser for extracting answers from completions. Defaults to vf.Parser().
bool
default:"False"
Whether to parallelize judge API calls across multiple rollouts.
AsyncOpenAI | None
default:"None"
OpenAI client for judge model calls. Defaults to AsyncOpenAI() with environment API key.
str
default:"gpt-4.1-nano"
Model identifier for the judge. Can be any OpenAI-compatible model.
dict[str, Any] | None
default:"None"
Additional sampling parameters for judge completions (e.g., temperature, max_tokens).
str
default:"DEFAULT_JUDGE_PROMPT"
Template for judge prompts. Must include {question}, {answer}, and {response} placeholders.

Default Judge Prompt

The default prompt template is:

Methods

judge

Call the judge model to evaluate a response. Caches results in state["judge_response"] if state is provided.
Messages
The input prompt (either string or list of message dicts).
Messages
The model’s completion to evaluate.
str
Ground truth answer for comparison.
State | None
default:"None"
Optional state dict for caching judge responses.
Returns: str - The judge model’s response (typically “yes” or “no”).
Judge responses are cached by prompt to avoid redundant API calls for the same evaluation.

Inherited Methods

All methods from Rubric are available:
  • add_reward_func(func, weight=1.0)
  • add_metric(func, weight=0.0)
  • score_rollout(state)
  • score_group(states)
See the Rubric documentation for details.

Class Objects

The following objects are automatically available to reward functions:
callable
The judge() method, callable as judge(prompt, completion, answer, state=None).
AsyncOpenAI
The OpenAI client instance.
str
The judge model identifier.
str
The judge prompt template.
dict
Sampling arguments for judge calls.
Parser
The parser instance.

Example Usage

Basic Judge Scoring

Custom Judge Prompt

Using Judge in Reward Functions

Error Handling

Notes

Judge API calls can be slow and expensive. Consider:
  • Using cheaper/faster models like gpt-4.1-nano for high-throughput evaluations
  • Caching judge responses by passing state parameter
  • Setting appropriate timeouts in judge_sampling_args
The max_tokens parameter is automatically converted to max_completion_tokens for compatibility with OpenAI’s chat API.

See Also