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
↑ Affected analytics, scorer metrics IO and model checks: 891 passed, 4 platform skips. ↑ Invalid-count and public subnormal-precision regressions demonstrated failures before repair. ↓ Live scorer experiment not independently rerun; final-head CI is not yet complete.
Description
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:
calibrate_outcome_statistics() in pyrit/analytics/calibration.py takes ScorerMetricsWithIdentity[ObjectiveScorerMetrics] directly, retaining the existing scorer provenance. It requires stored confusion counts (true_positive, false_positive, true_negative, false_negative), both gold classes, and num_scorer_trials == 1. Missing counts or multi-trial metrics raise ValueError; the shipped three-trial registry entries must be evaluated again with one trial before use.
CalibratedOutcomeStatistics holds the original outcomes and scorer_metrics alongside the clipped Rogan-Gladen point estimate and closed-form Lang-Reiczigel (2014) confidence bounds in an isolated Decimal context. It shares the public Wilson and outward-rounding helpers in pyrit.models.analytics, and derives warning messages from its warning codes.
Built-in reliability and scope guards: if Youden's index (sensitivity + specificity - 1) is at or below 0.20 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. Calibrated outputs are also suppressed when the observed rate is inconsistent with the metrics (the Lang-Reiczigel interval lies entirely outside [0, 1]). It also surfaces structured warnings for low decided_share and clipped boundary estimates, and supports an optional expected_eval_hash check against an independently supplied scorer evaluation hash.
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.
Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
1d3c6acd2a32ab61da41549003ff46bda9412d11↑ Invalid-count and public subnormal-precision regressions demonstrated failures before repair.
↓ Live scorer experiment not independently rerun; final-head CI is not yet complete.
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:
calibrate_outcome_statistics()inpyrit/analytics/calibration.pytakesScorerMetricsWithIdentity[ObjectiveScorerMetrics]directly, retaining the existing scorer provenance. It requires stored confusion counts (true_positive,false_positive,true_negative,false_negative), both gold classes, andnum_scorer_trials == 1. Missing counts or multi-trial metrics raiseValueError; the shipped three-trial registry entries must be evaluated again with one trial before use.CalibratedOutcomeStatisticsholds the originaloutcomesandscorer_metricsalongside the clipped Rogan-Gladen point estimate and closed-form Lang-Reiczigel (2014) confidence bounds in an isolatedDecimalcontext. It shares the public Wilson and outward-rounding helpers inpyrit.models.analytics, and derives warning messages from its warning codes.sensitivity + specificity - 1) is at or below0.20or 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. Calibrated outputs are also suppressed when the observed rate is inconsistent with the metrics (the Lang-Reiczigel interval lies entirely outside[0, 1]). It also surfaces structured warnings for lowdecided_shareand clipped boundary estimates, and supports an optionalexpected_eval_hashcheck against an independently supplied scorer evaluation hash.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)