Each autograder uses a specialized system prompt optimized for its evaluation approach:
PerCriterionGrader - Detailed criterion-by-criterion evaluation with strict JSON formatting requirements. The prompt instructs the LLM to evaluate each criterion independently, handling both positive and negative criteria with specific response formats.
PerCriterionOneShotGrader - Streamlined prompt for evaluating all criteria in a single response. Focuses on providing verdicts (MET/UNMET) and explanations for each criterion in a structured JSON format.
RubricAsJudgeGrader - Holistic evaluation prompt that asks the LLM to consider the output as a whole and provide a single overall score from 0-100, taking into account the weights of all criteria.
You can view the complete default prompts in the source files:
Customizing System Prompts: You can override the default system prompt by passing a system_prompt parameter to any autograder:
grader = PerCriterionGrader(
generate_fn=your_function,
system_prompt="Your custom system prompt here"
)
XML Tag Structure: The autograders wrap content in <response> XML tags. If a query is provided (optional), it's wrapped in <query> tags. If you provide a custom system prompt, ensure it handles the response structure you're using:
<!-- Plain string response -->
<response>
{content}
</response>
<!-- Or nested with thinking/output -->
<response>
<thinking>{thinking_content}</thinking>
<output>{output_content}</output>
</response>
The structure depends on what you pass to rubric.grade(). Customize your system prompt to handle your preferred format.
Customization
You can customize grading at multiple levels:
1. Custom generate_fn (most common)
Pass any typed function that returns a Pydantic model. Use any LLM provider (OpenAI, Anthropic, local models, etc.):
from rubric import PerCriterionOutput
async def your_custom_function(system_prompt: str, user_prompt: str) -> PerCriterionOutput:
# Your LLM call here with structured outputs
...
return PerCriterionOutput(criterion_status="MET", explanation="...")
grader = PerCriterionGrader(generate_fn=your_custom_function)
Each autograder requires a specific return type:
PerCriterionGrader → PerCriterionOutput
PerCriterionOneShotGrader → OneShotOutput
RubricAsJudgeGrader → RubricAsJudgeOutput
2. Create custom autograder
Subclass Autograder and implement the abstract methods:
judge() - Evaluates the submission and returns raw results
aggregate() - Transforms judge results into an EvaluationReport
The generate_fn pattern is optional - you can make LLM calls directly, use multiple functions, or skip LLMs entirely.
3. Override system prompts
Customize the default prompts for built-in autograders:
grader = PerCriterionGrader(
generate_fn=your_function,
system_prompt="Your custom system prompt here"
)
Error Handling
Since v2.0.0, validation happens at generation time via Pydantic models. Your generate_fn is responsible for:
Structured outputs - Use your LLM provider's structured output features (JSON schema, function calling, etc.) to ensure valid responses
Retry logic - Implement retries within your generate_fn if needed
Validation - Return a validated Pydantic model (PerCriterionOutput, OneShotOutput, or RubricAsJudgeOutput)
If your generate_fn returns invalid data, Pydantic will raise a ValidationError.
Example with retries:
from pydantic import ValidationError
from rubric import PerCriterionOutput
async def generate_with_retries(system_prompt: str, user_prompt: str, max_retries: int = 3) -> PerCriterionOutput:
for attempt in range(max_retries):
try:
response = await your_llm_call(system_prompt, user_prompt)
return PerCriterionOutput.model_validate_json(response)
except ValidationError as e:
if attempt == max_retries - 1:
raise
continue # Retry on validation error
Best practice: Use structured outputs (JSON schema constrained decoding) in your LLM client to avoid validation errors entirely.
Score Fields
Field
Description
score
Final score. 0-1 when normalize=True (default), raw_score when normalize=False.
raw_score
Raw weighted sum. Consistent across all graders.
llm_raw_score
Original LLM output. For RubricAsJudgeGrader: 0-100 score. For others: same as raw_score.
report
Per-criterion breakdown (None for RubricAsJudgeGrader).
The normalize Parameter
# Default: normalized 0-1 scores
grader = PerCriterionGrader(generate_fn=your_function)
result = await rubric.grade(text, autograder=grader)
print(result.score) # 0.85 (normalized)
print(result.raw_score) # 12.75 (raw weighted sum)
# Raw scores
grader = PerCriterionGrader(generate_fn=your_function, normalize=False)
result = await rubric.grade(text, autograder=grader)
print(result.score) # 12.75 (raw, can be negative)
print(result.raw_score) # 12.75 (same as score)
Loading Rubrics
# Direct construction
rubric = Rubric([
Criterion(weight=10.0, requirement="States Q4 2023 base margin as 17.2%"),
Criterion(weight=8.0, requirement="Explicitly uses Shapley attribution for decomposition"),
Criterion(weight=-15.0, requirement="Uses total deliveries instead of cash-only deliveries")
])
# From list of dictionaries
rubric = Rubric.from_dict([
{"weight": 10.0, "requirement": "States Q4 2023 base margin as 17.2%"},
{"weight": 8.0, "requirement": "Explicitly uses Shapley attribution for decomposition"},
{"weight": -15.0, "requirement": "Uses total deliveries instead of cash-only deliveries"}
])
# From JSON string
rubric = Rubric.from_json('[{"weight": 10.0, "requirement": "Example requirement"}]')
# From YAML string
yaml_data = '''
- weight: 10.0
requirement: "Example requirement"
'''
rubric = Rubric.from_yaml(yaml_data)
# From files
rubric = Rubric.from_file('rubric.json')
rubric = Rubric.from_file('rubric.yaml')
JSON Format
[
{
"weight": 10.0,
"requirement": "States Q4 2023 base margin as 17.2%"
},
{
"weight": 8.0,
"requirement": "Explicitly uses Shapley attribution for decomposition"
},
{
"weight": -15.0,
"requirement": "Uses total deliveries instead of cash-only deliveries"
}
]
YAML Format
- weight: 10.0
requirement: "States Q4 2023 base margin as 17.2%"
- weight: 8.0
requirement: "Explicitly uses Shapley attribution for decomposition"
- weight: -15.0
requirement: "Uses total deliveries instead of cash-only deliveries"
Requirements
Python 3.10+
An LLM API (e.g., OpenAI, Anthropic, OpenRouter) - set appropriate API keys as environment variables