Judge
Unified LLM-as-judge for evaluating agent outputs
How It Works
Quick Start
Accuracy Check
from praisonaiagents.eval import Judge
result = Judge().run(output="4", expected="4")
print(f"Score: {result.score}/10")
print(f"Passed: {result.passed}")Criteria Check
from praisonaiagents.eval import Judge
judge = Judge(criteria="Response is helpful and accurate")
result = judge.run(output="Hello! How can I help you today?")
print(f"Score: {result.score}/10")With Agent
from praisonaiagents import Agent
from praisonaiagents.eval import Judge
agent = Agent(instructions="You are a math tutor")
result = Judge().run(
agent=agent,
input_text="What is 2+2?",
expected="4"
)Judge Types
Configuration
model
stringLLM model to use for judging
temperature
floatTemperature for LLM calls (lower = more consistent)
threshold
floatScore threshold for passing (1-10 scale)
criteria
stringCustom criteria for evaluation
from praisonaiagents.eval import Judge, JudgeConfig
config = JudgeConfig(
model="gpt-4o",
temperature=0.1,
threshold=8.0,
criteria="Response is accurate and well-formatted"
)
judge = Judge(config=config)Custom Judges
- Create Custom Judge
python from praisonaiagents.eval import Judge class RecipeJudge(Judge): """Judge for evaluating recipe quality.""" CRITERIA_PROMPT = """Evaluate this recipe: CRITERIA: Recipe is complete with ingredients and steps RECIPE: {output} Score 1-10 based on completeness and clarity. SCORE: [1-10] REASONING: [explanation] """ - Register Judge
python from praisonaiagents.eval import add_judge add_judge("recipe", RecipeJudge) - Use Judge
python from praisonaiagents.eval import get_judge RecipeJudge = get_judge("recipe") judge = RecipeJudge() result = judge.run(output=recipe_text)
Response format
A custom judge’s prompt asks the model for a SCORE: line and a REASONING: line, which the shared parser turns into a numeric score and an explanation.
SCORE: 8
REASONING: Complete recipe with clear ingredients and steps.| Rule | Behaviour |
|---|---|
| Label match | SCORE: and REASONING: are matched at the start of a line. Markdown-bolded (SCORE: 1) and bullet-prefixed labels are tolerated. |
| Score clamping | Values below 1 become 1.0; values above 10 become 10.0. |
| Unparseable score | If no numeric score can be read, the verdict fails closed — score=1.0, passed=False, reasoning="Unable to parse response". |
| Shared parser | AccuracyEvaluator, CriteriaEvaluator, and ComparisonEvaluator all parse responses with parse_score_reasoning from praisonaiagents.eval. |
Registry Functions
| Function | Description |
|---|---|
add_judge(name, class) | Register a custom judge |
get_judge(name) | Get a judge class by name |
list_judges() | List all registered judges |
remove_judge(name) | Remove a registered judge |
from praisonaiagents.eval import add_judge, get_judge, list_judges
# List available judges
print(list_judges()) # ['accuracy', 'criteria']
# Get a judge
AccuracyJudge = get_judge("accuracy")The same registry is reachable from the shell:
praisonai eval list # short form — preferred
praisonai eval list-judges # long form — still supportedOutput:
Registered Judge Types:
- accuracy
- criteria
- recipeJudgeResult
ResponseField
floatQuality score from 1-10
ResponseField
boolTrue only when a numeric score was parsed AND score >= threshold. An unparseable verdict is always passed=False.
ResponseField
stringExplanation for the score
ResponseField
listImprovement suggestions
result = judge.run(output="Hello!")
print(result.score) # 8.5
print(result.passed) # True
print(result.reasoning) # "Good greeting..."
print(result.suggestions) # ["Could add more context"]
print(result.to_dict()) # Full dictionaryCLI Usage
praisonai eval judge --output "4" --expected "4"praisonai eval judge --output "Hello!" --criteria "Response is friendly"praisonai eval judge --file output.txt --criteria "Code is correct"praisonai eval listpraisonai eval list-judgesAsync Support
import asyncio
from praisonaiagents.eval import Judge
async def evaluate():
judge = Judge(criteria="Response is helpful")
result = await judge.run_async(output="Hello!")
return result
result = asyncio.run(evaluate())Best Practices
Choose the Right Mode
- Use accuracy mode when you have a known expected output
- Use criteria mode for subjective quality evaluation
- Create custom judges for domain-specific evaluation
Set Appropriate Thresholds
- Default threshold is 7.0 (70%)
- Increase for critical evaluations
- Decrease for exploratory testing
Use Specific Criteria
- Be specific in your criteria
- Include measurable aspects
- Avoid vague terms like “good” or “nice”