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
)
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)
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. Options: "mean", "median", "weighted_mean", "mode".
TYPE:
|
nominal_aggregation
|
Strategy for aggregating nominal multi-choice votes. Options: "mode", "weighted_mode", "unanimous".
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:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If neither llm_config nor judges is provided, or both are provided. |
Source code in src/autorubric/graders/criterion_grader.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |
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
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 | |
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
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 | |
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:
|