You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds an opt-in helper in pyrit.analytics that adjusts a decided attack success rate (OutcomeStatistics.success_rate_decided) for an objective scorer's known false-positive and false-negative rates, while leaving compute_outcome_statistics() completely unchanged (Phase 2 of #3579, building on #3889).
Raw attack success rates treat the judge as 100% accurate. When two cohorts are scored by judges with different sensitivity and specificity, raw numbers can flip which model looks safer. On a 50-sample live gpt-4o-mini run comparing a lenient refusal inverter (Se=0.925, Sp=0.775) against a 0.9 scale threshold scorer (Se=0.625, Sp=0.975):
Cohort
True ASR
Raw ASR (95% Wilson CI)
Calibrated ASR (95% Lang-Reiczigel CI)
Model A (Scale >= 0.9)
30.0%
18.0% ([9.8%, 30.8%])
25.8% ([9.1%, 50.0%])
Model B (Refusal Inverter)
14.0%
34.0% ([22.4%, 47.8%])
16.4% ([0.0%, 38.8%])
Raw scores made the 2x safer model look almost twice as vulnerable, and its Wilson interval missed the true 14.0% rate. Calibration restores the true ranking and widens the interval honestly to include uncertainty from both the attack cohort and the judge evaluation set.
What this PR adds:
JudgeCalibrationProfile in pyrit/analytics/calibration.py to hold a judge's confusion counts (true_positive, false_positive, true_negative, false_negative) alongside dataset and scorer provenance (eval_hash, scorer_hash, scorer_class_name, dataset_name, dataset_version, num_scorer_trials, and counts_source). It reads stored counts from FEAT: Persist scorer specificity and add Wilson CI to outcome statistics #3889 directly and can also recover exact verified integer counts for existing objective_achieved_metrics.jsonl entries that have not been re-run yet.
calibrate_outcome_statistics() returning CalibratedOutcomeStatistics with the clipped Rogan-Gladen point estimate, closed-form Lang-Reiczigel (2014) confidence bounds in an isolated Decimal context (matching the subnormal outward-rounding behavior from FEAT: Persist scorer specificity and add Wilson CI to outcome statistics #3889), and the original unadjusted rate and Wilson bounds side by side.
Built-in reliability and scope guards: if Youden's index (sensitivity + specificity - 1) is at or below min_youden_index (0.20 by default) or its MOVER-Wilson lower confidence bound is at or below 0.0, calibrated outputs are suppressed (None, is_reliable=False) so weak or tiny-sample judges cannot produce misleading numbers. It also surfaces structured warnings for low decided_share, multi-trial majority-vote calibration, and clipped boundary estimates, and supports an optional expected_eval_hash check to block wrong-judge mix-ups.
Lazy exports in pyrit/analytics/__init__.py and opt-in usage notes in doc/code/analytics/0_attack_results.md.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Registry-built profiles lose the persisted evaluation hash, breaking matching live-scorer binding, while fixed-precision calculations produce incorrect probabilities and interval bounds for very large cohorts.
Adds opt-in judge calibration to PyRIT analytics, building on #3889’s stored scorer metrics and Wilson intervals. Callers can adjust decided success rates for measured judge errors without changing compute_outcome_statistics().
Changes:
Adds calibration profiles using stored or verified recovered confusion counts, with scorer and dataset provenance.
Reports calibrated estimates and confidence bounds alongside observed rates, with reliability checks and structured warnings.
Adds lazy public exports, usage documentation, and numerical and edge-case tests.
File
Description
tests/unit/analytics/test_calibration.py
Tests calibration formulas, profile recovery, validation, warnings, and numerical boundaries.
pyrit/analytics/calibration.py
Implements calibration profiles, estimates, confidence intervals, and reliability checks.
pyrit/analytics/__init__.py
Lazily exports the calibration API.
doc/code/analytics/0_attack_results.md
Documents opt-in usage, assumptions, and reliability behavior.
Preserved persisted eval_hash in _load_metrics_from_file() via ComponentIdentifier.with_eval_hash() so registry-loaded ScorerMetricsWithIdentity profiles retain their evaluation hash and bind cleanly against live scorers (expected_eval_hash), with round-trip and non-null shipped-registry tests.
Replaced the fixed 50-digit context in pyrit/analytics/calibration.py with bit-length-scaled Decimal precision and cancellation-free complement terms across all calibration helpers, adding regression tests for 10**100 (1 success out of 10**100, near-1, and tiny Youden's J) as well as 10**5000.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The confidence-level transformation mishandles valid extreme inputs, either raising StatisticsError or collapsing intervals to zero and removing the Youden guard’s uncertainty penalty.
The validated range includes values that this floating-point transformation cannot handle. For confidence_level=0.9999999999999999, the argument rounds to 1.0 and inv_cdf raises StatisticsError; for 1e-20, it rounds to 0.5 and returns zero, collapsing the intervals and removing the uncertainty penalty from the Youden guard. Compute the quantile from the lower tail to avoid rounding to 1.0, and explicitly reject levels too small to produce a positive quantile.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The Lang–Reiczigel correction and MOVER reliability guard require independent statistical review because the reference tests repeat the implemented equations and do not independently establish confidence-interval coverage.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds an opt-in helper in
pyrit.analyticsthat adjusts a decided attack success rate (OutcomeStatistics.success_rate_decided) for an objective scorer's known false-positive and false-negative rates, while leavingcompute_outcome_statistics()completely unchanged (Phase 2 of #3579, building on #3889).Raw attack success rates treat the judge as 100% accurate. When two cohorts are scored by judges with different sensitivity and specificity, raw numbers can flip which model looks safer. On a 50-sample live
gpt-4o-minirun comparing a lenient refusal inverter (Se=0.925, Sp=0.775) against a0.9scale threshold scorer (Se=0.625, Sp=0.975):[9.8%, 30.8%])[9.1%, 50.0%])[22.4%, 47.8%])[0.0%, 38.8%])Raw scores made the 2x safer model look almost twice as vulnerable, and its Wilson interval missed the true 14.0% rate. Calibration restores the true ranking and widens the interval honestly to include uncertainty from both the attack cohort and the judge evaluation set.
What this PR adds:
JudgeCalibrationProfileinpyrit/analytics/calibration.pyto hold a judge's confusion counts (true_positive,false_positive,true_negative,false_negative) alongside dataset and scorer provenance (eval_hash,scorer_hash,scorer_class_name,dataset_name,dataset_version,num_scorer_trials, andcounts_source). It reads stored counts from FEAT: Persist scorer specificity and add Wilson CI to outcome statistics #3889 directly and can also recover exact verified integer counts for existingobjective_achieved_metrics.jsonlentries that have not been re-run yet.calibrate_outcome_statistics()returningCalibratedOutcomeStatisticswith the clipped Rogan-Gladen point estimate, closed-form Lang-Reiczigel (2014) confidence bounds in an isolatedDecimalcontext (matching the subnormal outward-rounding behavior from FEAT: Persist scorer specificity and add Wilson CI to outcome statistics #3889), and the original unadjusted rate and Wilson bounds side by side.sensitivity + specificity - 1) is at or belowmin_youden_index(0.20by default) or its MOVER-Wilson lower confidence bound is at or below0.0, calibrated outputs are suppressed (None,is_reliable=False) so weak or tiny-sample judges cannot produce misleading numbers. It also surfaces structured warnings for lowdecided_share, multi-trial majority-vote calibration, and clipped boundary estimates, and supports an optionalexpected_eval_hashcheck to block wrong-judge mix-ups.pyrit/analytics/__init__.pyand opt-in usage notes indoc/code/analytics/0_attack_results.md.Related to #3579 and #3889. CC Roman Lutz (@romanlutz) Richard Lundeen (@richlundeen) Qin Dai (@Allan-dq)