Judge API 參考 (Evaluation)
boring.judge
Judge Package - V10.25 Advanced Evaluation
Provides LLM-as-a-Judge evaluation capabilities including: - Code quality grading with customizable rubrics - Pairwise comparison with position bias detection - Evaluation metrics (Kappa, Spearman, F1) - Bias monitoring and reporting
BiasMonitor
Monitors systematic biases in LLM evaluation over time.
Features: - Track pairwise comparison outcomes - Detect position bias (first-position preference) - Detect length bias (longer responses get higher scores) - Generate bias reports with recommendations
Source code in src/boring/judge/bias_monitor.py
67 68 69 70 71 72 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 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 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 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 | |
__init__(project_root)
Initialize bias monitor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_root
|
Path
|
Project root for database storage |
required |
Source code in src/boring/judge/bias_monitor.py
record_pairwise_evaluation(evaluation_id, winner, first_position, position_consistent, confidence=0.0, response_a_length=0, response_b_length=0)
Record a pairwise comparison result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
evaluation_id
|
str
|
Unique identifier for this evaluation |
required |
winner
|
str
|
Winner of comparison ('A', 'B', 'TIE') |
required |
first_position
|
str
|
Which response was in first position ('A' or 'B') |
required |
position_consistent
|
bool
|
Whether both position passes agreed |
required |
confidence
|
float
|
Confidence score of the decision |
0.0
|
response_a_length
|
int
|
Length of response A |
0
|
response_b_length
|
int
|
Length of response B |
0
|
Source code in src/boring/judge/bias_monitor.py
record_direct_evaluation(evaluation_id, score, response_length, dimension_scores=None)
Record a direct scoring evaluation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
evaluation_id
|
str
|
Unique identifier for this evaluation |
required |
score
|
float
|
Overall score |
required |
response_length
|
int
|
Length of the response (characters or tokens) |
required |
dimension_scores
|
dict | None
|
Optional per-dimension scores |
None
|
Source code in src/boring/judge/bias_monitor.py
detect_position_bias(days=30)
Detect position bias in pairwise comparisons.
Checks if first-position responses win more often than expected (50%).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
days
|
int
|
Number of days to analyze |
30
|
Returns:
| Type | Description |
|---|---|
PositionBiasResult
|
PositionBiasResult with bias analysis |
Source code in src/boring/judge/bias_monitor.py
detect_length_bias(days=30)
Detect length bias in direct evaluations.
Checks if longer responses receive higher scores.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
days
|
int
|
Number of days to analyze |
30
|
Returns:
| Type | Description |
|---|---|
LengthBiasResult
|
LengthBiasResult with bias analysis |
Source code in src/boring/judge/bias_monitor.py
get_bias_report(days=30)
Generate comprehensive bias report.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
days
|
int
|
Number of days to analyze |
30
|
Returns:
| Type | Description |
|---|---|
BiasReport
|
BiasReport with all bias analyses and recommendations |
Source code in src/boring/judge/bias_monitor.py
clear_old_data(days=90)
Clear evaluation data older than specified days.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
days
|
int
|
Keep data from the last N days |
90
|
Source code in src/boring/judge/bias_monitor.py
BiasReport
dataclass
Comprehensive bias report.
Source code in src/boring/judge/bias_monitor.py
LengthBiasResult
dataclass
PositionBiasResult
dataclass
LLMJudge
LLM-as-a-Judge implementation for evaluating code and plans.
V10.25 Enhancements: - Confidence calibration based on position consistency - Length-normalized scoring to mitigate length bias - BiasMonitor integration for systematic bias tracking
Source code in src/boring/judge/core.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 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 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 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 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 | |
grade_code(filename, content, rubric=CODE_QUALITY_RUBRIC, interactive=False)
Evaluate code quality against a rubric. If interactive=True, returns the PROMPT for the user to execute using their IDE AI. Else, executes via CLI adapter.
Source code in src/boring/judge/core.py
compare_plans(plan_a, plan_b, context, interactive=False)
Compare two implementation plans and pick a winner.
Implements Pairwise Comparison with Position Bias Mitigation.
Source code in src/boring/judge/core.py
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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
compare_code(name_a, code_a, name_b, code_b, context=None, interactive=False)
Compare two code implementations (A/B Test).
Source code in src/boring/judge/core.py
calibrate_confidence(raw_confidence, position_consistent, evidence_count=0)
Calibrate confidence based on multiple signals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw_confidence
|
float
|
Raw confidence from model output (0-1) |
required |
position_consistent
|
bool
|
Whether position swap passes agreed |
required |
evidence_count
|
int
|
Number of evidence items supporting the judgment |
0
|
Returns:
| Type | Description |
|---|---|
float
|
Calibrated confidence score (0-1) |
Source code in src/boring/judge/core.py
length_normalized_score(score, response_length, target_length=500, max_penalty=0.5)
Adjust score based on response length to mitigate length bias.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
score
|
float
|
Original score |
required |
response_length
|
int
|
Length of the response (characters) |
required |
target_length
|
int
|
Expected typical length |
500
|
max_penalty
|
float
|
Maximum penalty to apply |
0.5
|
Returns:
| Type | Description |
|---|---|
float
|
Length-adjusted score |
Source code in src/boring/judge/core.py
get_bias_report(days=30)
Get bias monitoring report.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
days
|
int
|
Number of days to analyze |
30
|
Returns:
| Type | Description |
|---|---|
dict | None
|
Bias report dict or None if monitoring not available |
Source code in src/boring/judge/core.py
DetailedCriterion
dataclass
A criterion with detailed level descriptions.
Source code in src/boring/judge/rubric_generator.py
DetailedRubric
dataclass
A complete rubric with all level descriptions and edge cases.
Source code in src/boring/judge/rubric_generator.py
EdgeCase
dataclass
RubricLevel
dataclass
A level in the rubric with detailed description.
Source code in src/boring/judge/rubric_generator.py
format_bias_report(report)
Format bias report as markdown.
Source code in src/boring/judge/bias_monitor.py
get_bias_monitor(project_root)
Get or create bias monitor singleton.
create_judge_provider()
Factory to create the appropriate LLM provider based on config.
Source code in src/boring/judge/factory.py
agreement_metrics(judge1, judge2, ordinal=False)
Calculate all agreement metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
judge1
|
list
|
Ratings from first judge |
required |
judge2
|
list
|
Ratings from second judge |
required |
ordinal
|
bool
|
If True, calculate weighted kappa for ordinal scales |
False
|
Returns:
| Type | Description |
|---|---|
AgreementMetrics
|
AgreementMetrics with all metrics |
Source code in src/boring/judge/metrics.py
classification_metrics(predictions, ground_truth)
Calculate all classification metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions
|
list[int]
|
List of predicted labels |
required |
ground_truth
|
list[int]
|
List of actual labels |
required |
Returns:
| Type | Description |
|---|---|
ClassificationMetrics
|
ClassificationMetrics with all metrics |
Source code in src/boring/judge/metrics.py
cohens_kappa(judge1, judge2)
Calculate Cohen's Kappa for inter-rater agreement.
κ = (Observed Agreement - Expected Agreement) / (1 - Expected Agreement)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
judge1
|
list
|
Ratings from first judge |
required |
judge2
|
list
|
Ratings from second judge |
required |
Returns:
| Type | Description |
|---|---|
float
|
Cohen's Kappa (-1.0 to 1.0) |
Source code in src/boring/judge/metrics.py
correlation_metrics(scores1, scores2)
Calculate all correlation metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scores1
|
list[float]
|
First set of scores |
required |
scores2
|
list[float]
|
Second set of scores |
required |
Returns:
| Type | Description |
|---|---|
CorrelationMetrics
|
CorrelationMetrics with all metrics |
Source code in src/boring/judge/metrics.py
f1_score(predictions, ground_truth)
Calculate F1 score: 2 * (precision * recall) / (precision + recall)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions
|
list[int]
|
List of predicted labels |
required |
ground_truth
|
list[int]
|
List of actual labels |
required |
Returns:
| Type | Description |
|---|---|
float
|
F1 score (0.0 to 1.0) |
Source code in src/boring/judge/metrics.py
format_metrics_report(report)
Format metrics report as markdown.
Source code in src/boring/judge/metrics.py
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 | |
generate_metrics_report(automated_scores=None, human_scores=None, predictions=None, ground_truth=None, pairwise_comparisons=None, evaluation_type='general')
Generate comprehensive evaluation metrics report.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
automated_scores
|
list[float] | None
|
Scores from automated evaluation |
None
|
human_scores
|
list[float] | None
|
Scores from human evaluation |
None
|
predictions
|
list[int] | None
|
Binary predictions (for classification) |
None
|
ground_truth
|
list[int] | None
|
Ground truth labels (for classification) |
None
|
pairwise_comparisons
|
list[dict] | None
|
Pairwise comparison results |
None
|
evaluation_type
|
str
|
Type of evaluation (ordinal, binary, pairwise) |
'general'
|
Returns:
| Type | Description |
|---|---|
EvaluationMetricsReport
|
EvaluationMetricsReport with all applicable metrics |
Source code in src/boring/judge/metrics.py
kendalls_tau(scores1, scores2)
Calculate Kendall's tau correlation coefficient.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scores1
|
list[float]
|
First set of scores |
required |
scores2
|
list[float]
|
Second set of scores |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Tuple of (tau, p_value) |
Source code in src/boring/judge/metrics.py
pairwise_metrics(comparisons)
Calculate all pairwise comparison metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
comparisons
|
list[dict]
|
List of comparison results with 'winner' and 'position_consistent' fields |
required |
Returns:
| Type | Description |
|---|---|
PairwiseMetrics
|
PairwiseMetrics with all metrics |
Source code in src/boring/judge/metrics.py
pearsons_r(scores1, scores2)
Calculate Pearson's correlation coefficient.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scores1
|
list[float]
|
First set of scores |
required |
scores2
|
list[float]
|
Second set of scores |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Tuple of (r, p_value) |
Source code in src/boring/judge/metrics.py
precision(predictions, ground_truth)
Calculate precision: TP / (TP + FP)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions
|
list[int]
|
List of predicted labels (1 = positive, 0 = negative) |
required |
ground_truth
|
list[int]
|
List of actual labels |
required |
Returns:
| Type | Description |
|---|---|
float
|
Precision score (0.0 to 1.0) |
Source code in src/boring/judge/metrics.py
recall(predictions, ground_truth)
Calculate recall: TP / (TP + FN)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions
|
list[int]
|
List of predicted labels |
required |
ground_truth
|
list[int]
|
List of actual labels |
required |
Returns:
| Type | Description |
|---|---|
float
|
Recall score (0.0 to 1.0) |
Source code in src/boring/judge/metrics.py
spearmans_rho(scores1, scores2)
Calculate Spearman's rank correlation coefficient.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scores1
|
list[float]
|
First set of scores |
required |
scores2
|
list[float]
|
Second set of scores |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Tuple of (rho, p_value) |
Source code in src/boring/judge/metrics.py
weighted_kappa(judge1, judge2, weights='quadratic')
Calculate weighted Cohen's Kappa for ordinal scales.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
judge1
|
list[int]
|
Ratings from first judge (ordinal integers) |
required |
judge2
|
list[int]
|
Ratings from second judge (ordinal integers) |
required |
weights
|
str
|
Weighting scheme - 'linear' or 'quadratic' |
'quadratic'
|
Returns:
| Type | Description |
|---|---|
float
|
Weighted Kappa (-1.0 to 1.0) |
Source code in src/boring/judge/metrics.py
format_rubric_json(rubric)
Convert rubric to JSON-serializable dict.
Source code in src/boring/judge/rubric_generator.py
generate_code_quality_rubric(strictness='balanced')
Generate a standard code quality rubric.
Source code in src/boring/judge/rubric_generator.py
generate_rubric(name, description, domain, criteria_names, scale='1-5', strictness='balanced', weights=None)
Generate a detailed rubric with level descriptions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the rubric |
required |
description
|
str
|
Description of what this rubric evaluates |
required |
domain
|
str
|
Domain for level templates (code_quality, security, performance, documentation) |
required |
criteria_names
|
list[str]
|
List of criterion names |
required |
scale
|
str
|
Rating scale (1-3, 1-5, 1-10) |
'1-5'
|
strictness
|
str
|
Strictness level (lenient, balanced, strict) |
'balanced'
|
weights
|
dict[str, float] | None
|
Optional weights for each criterion |
None
|
Returns:
| Type | Description |
|---|---|
DetailedRubric
|
DetailedRubric with complete level descriptions |
Source code in src/boring/judge/rubric_generator.py
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 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 | |
generate_security_rubric(strictness='strict')
Generate a security-focused rubric.
Source code in src/boring/judge/rubric_generator.py
rubric_to_prompt(rubric)
Convert a DetailedRubric to a prompt string for LLM evaluation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rubric
|
DetailedRubric
|
The rubric to convert |
required |
Returns:
| Type | Description |
|---|---|
str
|
Formatted prompt string |