Graders¶
Grader implementations for evaluating responses against rubrics.
Overview¶
Graders evaluate responses against rubrics and return structured reports. The main implementation is CriterionGrader, which supports single LLM, ensemble, and few-shot modes. All combinations work orthogonally.
Quick Example¶
from autorubric import LLMConfig, FewShotConfig
from autorubric.graders import CriterionGrader, JudgeSpec, Grader
# Single LLM mode
grader = CriterionGrader(
llm_config=LLMConfig(model="openai/gpt-4.1-mini"),
)
# With custom system prompt
grader = CriterionGrader(
llm_config=LLMConfig(model="openai/gpt-4.1-mini"),
system_prompt="You are evaluating technical documentation...",
)
# Ensemble mode
grader = CriterionGrader(
judges=[
JudgeSpec(LLMConfig(model="gemini/gemini-3-flash-preview"), "gemini", weight=1.0),
JudgeSpec(LLMConfig(model="anthropic/claude-sonnet-4-5-20250929"), "claude", weight=1.2),
],
aggregation="weighted",
)
# Single LLM + few-shot
grader = CriterionGrader(
llm_config=LLMConfig(model="openai/gpt-4.1-mini"),
training_data=train_data,
few_shot_config=FewShotConfig(n_examples=3, balance_verdicts=True),
)
# Grade
result = await rubric.grade(to_grade=response, grader=grader)
Grading Options¶
grader = CriterionGrader(
llm_config=LLMConfig(model="openai/gpt-4.1-mini"),
# Score normalization
normalize=True, # True: 0-1 range, False: raw weighted sum
# CANNOT_ASSESS handling
cannot_assess_config=CannotAssessConfig(strategy=CannotAssessStrategy.SKIP),
# Length penalty
length_penalty=LengthPenalty(free_budget=6000, max_cap=8000),
# Position bias mitigation (for multi-choice)
shuffle_options=True, # Default: enabled
# Multi-choice abstain channel
auto_na_option=True, # Default: True — guarantees every multi-choice criterion a
# first-class NA/abstain option (auto-injected if absent).
# Set False for forced-choice (no auto NA option).
# Reproducibility — pins all non-LLM randomness (shuffles, few-shot selection)
seed=42, # Default: auto-generated
)
With auto_na_option=True, an auto-injected NA option is appended at the end (highest index), so existing option indices are preserved; an author-supplied NA option is never stripped.
CriterionGrader¶
Main grader with support for single LLM, ensemble, and few-shot modes.
CriterionGrader
¶
CriterionGrader(*, llm_config: LLMConfig | None = None, judges: list[JudgeSpec] | None = None, aggregation: AggregationStrategy = 'majority', ordinal_aggregation: OrdinalAggregation = 'mean', nominal_aggregation: NominalAggregation = 'mode', training_data: RubricDataset | None = None, few_shot_config: FewShotConfig | None = None, system_prompt: str | None = None, multi_choice_system_prompt: str | None = None, length_penalty: LengthPenalty | None = None, normalize: bool = True, cannot_assess_config: CannotAssessConfig | None = None, shuffle_options: bool = True, auto_na_option: bool = True, seed: int | None = None, binary_response_format: type[BaseModel] | None = None, multi_choice_response_format: type[BaseModel] | None = None)
Bases: Grader
Unified criterion-based grader with compositional few-shot and ensemble support.
This grader evaluates each criterion independently and supports: - Single LLM mode (via llm_config) - Ensemble mode with multiple judges (via judges) - Few-shot prompting (via training_data + few_shot_config)
All combinations work: single LLM, single + few-shot, ensemble, ensemble + few-shot.
Parameters are orthogonal: - llm_config OR judges: Choose single-LLM or ensemble mode - training_data + few_shot_config: Enable few-shot prompting (applies to all judges)
Example
from autorubric import LLMConfig, FewShotConfig, RubricDataset from autorubric.graders import CriterionGrader, JudgeSpec
Single LLM¶
grader = CriterionGrader(llm_config=LLMConfig(model="gemini/gemini-3-flash-preview"))
Single LLM + few-shot¶
train, test = dataset.split_train_test(n_train=100) grader = CriterionGrader( ... llm_config=LLMConfig(model="gemini/gemini-3-flash-preview"), ... training_data=train, ... few_shot_config=FewShotConfig(n_examples=3), ... )
Ensemble¶
grader = CriterionGrader( ... judges=[ ... JudgeSpec(LLMConfig(model="gemini/gemini-3-flash-preview"), "gemini"), ... JudgeSpec(LLMConfig(model="anthropic/claude-sonnet-4-5-20250929"), "claude"), ... ], ... aggregation="majority", ... )
Ensemble + few-shot¶
grader = CriterionGrader( ... judges=[JudgeSpec(...), JudgeSpec(...)], ... aggregation="majority", ... training_data=train, ... few_shot_config=FewShotConfig(n_examples=3), ... )
Initialize the criterion grader.
| PARAMETER | DESCRIPTION |
|---|---|
llm_config
|
Configuration for single-LLM mode. Mutually exclusive with judges.
TYPE:
|
judges
|
List of JudgeSpec for ensemble mode. Mutually exclusive with llm_config.
TYPE:
|
aggregation
|
Strategy for aggregating votes in ensemble mode (binary criteria).
TYPE:
|
ordinal_aggregation
|
Strategy for aggregating ordinal multi-choice votes. Central tendency: "mean", "median", "weighted_mean", "mode". Conservative/ permissive (analogs of binary unanimous/any): "min" (lowest selected option) / "max" (highest selected option).
TYPE:
|
nominal_aggregation
|
Strategy for aggregating nominal multi-choice votes. Options: "mode", "weighted_mode", "unanimous". "unanimous" abstains via the NA option on disagreement, or falls back to mode + warns if there is no NA option.
TYPE:
|
training_data
|
Dataset for few-shot examples. If provided, enables few-shot prompting.
TYPE:
|
few_shot_config
|
Configuration for few-shot example selection.
TYPE:
|
system_prompt
|
Custom system prompt for binary criteria.
TYPE:
|
multi_choice_system_prompt
|
Custom system prompt for multi-choice criteria.
TYPE:
|
length_penalty
|
Optional length penalty configuration.
TYPE:
|
normalize
|
If True, normalize score to [0, 1]. If False, return raw sum.
TYPE:
|
cannot_assess_config
|
Configuration for handling CANNOT_ASSESS verdicts.
TYPE:
|
shuffle_options
|
If True (default), randomize the order of multi-choice options presented to the LLM to mitigate position bias. Each judge/call sees a different random order, and responses are mapped back to original indices. Disable for deterministic behavior in tests.
TYPE:
|
auto_na_option
|
If True (default), auto-inject a canonical NA / "cannot assess" option into any multi-choice criterion that lacks one, giving the judge a first-class abstain channel analogous to binary CANNOT_ASSESS. The injected option is appended at the end (highest index) so existing option indices are preserved. Set False for forced-choice classification (the judge must pick a scored option). Never strips an author-supplied NA option — author intent wins.
TYPE:
|
seed
|
Master seed for all non-LLM randomness (option shuffling, few-shot
example selection). Auto-generated when None so that randomness is always
pinned and reproducible. Inspect via the
TYPE:
|
binary_response_format
|
Pydantic model to use as the structured output schema
for binary criterion judgments. Must be a subclass of (or compatible with)
CriterionJudgment. If the model includes an
TYPE:
|
multi_choice_response_format
|
Pydantic model to use as the structured output
schema for multi-choice criterion judgments. Must be a subclass of (or
compatible with) MultiChoiceJudgment. If the model includes an
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If neither llm_config nor judges is provided, or both are provided. |
Source code in src/autorubric/graders/criterion_grader.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 | |
judge
async
¶
judge(to_grade: str, rubric: list[Criterion], query: str | None = None, reference_submission: str | None = None) -> list[JudgeCriterionResults]
Judge all criteria with all judges (parallel across judges).
Source code in src/autorubric/graders/criterion_grader.py
aggregate
async
¶
aggregate(judge_results: list[JudgeCriterionResults], *, normalize: bool = True) -> EnsembleEvaluationReport
Aggregate results from all judges into final report.
Handles both binary and multi-choice criteria: - Binary: Uses JudgeVote and _aggregate_votes() - Multi-choice: Uses MultiChoiceJudgeVote and _aggregate_multi_choice_votes()
Source code in src/autorubric/graders/criterion_grader.py
959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 | |
Grader¶
Abstract base class for grader implementations.
Grader
¶
Grader(*, length_penalty: LengthPenalty | None = None, normalize: bool = True)
Bases: ABC
Base class for LLM-backed grading implementations.
All graders require an LLMConfig for the LLM client. Subclasses must implement judge() and aggregate() methods.
| PARAMETER | DESCRIPTION |
|---|---|
length_penalty
|
Optional configuration for penalizing overly long outputs. When provided, a penalty based on the token/word count is subtracted from the final score.
TYPE:
|
normalize
|
If True (default), scores are normalized to 0-1. If False, raw weighted sums are returned, which is useful for RL training scenarios.
TYPE:
|
Source code in src/autorubric/graders/base.py
judge
abstractmethod
async
¶
judge(to_grade: str, rubric: list[Criterion], query: str | None = None, reference_submission: str | None = None) -> Any
Collect raw judge results for the provided submission.
| PARAMETER | DESCRIPTION |
|---|---|
to_grade
|
The text to evaluate.
TYPE:
|
rubric
|
List of criteria to evaluate against.
TYPE:
|
query
|
Optional input/query that prompted the response.
TYPE:
|
reference_submission
|
Optional exemplar response for grading context.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Any
|
Raw judge results (format depends on implementation). |
Source code in src/autorubric/graders/base.py
aggregate
abstractmethod
async
¶
aggregate(judge_results: Any, *, normalize: bool = True) -> EvaluationReport
Transform judge results into an EvaluationReport.
| PARAMETER | DESCRIPTION |
|---|---|
judge_results
|
Raw results from judge().
TYPE:
|
normalize
|
If True, normalize score to 0-1. If False, return raw weighted sum.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
EvaluationReport
|
EvaluationReport with score and optional per-criterion breakdown. |
Source code in src/autorubric/graders/base.py
grade
async
¶
grade(to_grade: ToGradeInput, rubric: list[Criterion], query: str | None = None, reference_submission: str | None = None) -> EvaluationReport
Grade the submission against the rubric.
This is the main entry point for the grader.
| PARAMETER | DESCRIPTION |
|---|---|
to_grade
|
The text to evaluate. Can be either:
- A string (optionally with
TYPE:
|
rubric
|
List of criteria to evaluate against.
TYPE:
|
query
|
Optional input/query that prompted the response.
TYPE:
|
reference_submission
|
Optional exemplar response for grading context.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
EvaluationReport
|
EvaluationReport with score and optional per-criterion breakdown. |
EvaluationReport
|
If normalize=True (default), score is 0-1. If normalize=False, score is raw |
EvaluationReport
|
weighted sum. If length_penalty was configured, the penalty is subtracted from |
EvaluationReport
|
the score. The raw_score field contains the unnormalized weighted sum before |
EvaluationReport
|
length penalty. |
Source code in src/autorubric/graders/base.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
JudgeSpec¶
Configuration for a single judge in an ensemble.
JudgeSpec
dataclass
¶
JudgeSpec(llm_config: LLMConfig, judge_id: str, weight: float = 1.0)
Specification for a single judge in an ensemble.
| ATTRIBUTE | DESCRIPTION |
|---|---|
llm_config |
Configuration for this judge's LLM.
TYPE:
|
judge_id |
Unique identifier for this judge (e.g., "gpt-4", "claude-sonnet").
TYPE:
|
weight |
Voting weight for weighted aggregation (default 1.0).
TYPE:
|