Skip to content

FEAT: Report confidence intervals and scorer specificity alongside attack success rates in analytics #3579

Open

Description

@nithin42

compute_outcome_statistics() in pyrit/analytics/outcome_statistics.py reports success_rate as a bare proportion (successes / total_decided) with no confidence interval, while ObjectiveScorerEvaluator._compute_metrics() in pyrit/score/scorer_evaluation/scorer_evaluator.py computes true_negative on line 860 and discards it without storing specificity on ObjectiveScorerMetrics. Because PyRIT already evaluates objective scorers against human-labeled responses and exposes those metrics at runtime through TrueFalseScorer.get_scorer_metrics(), the two halves of the pipeline exist in the repo, yet the scorer's error rate is never connected to the reported attack success rate.

For example, the gpt-5.4 refusal inverter in objective_achieved_metrics.jsonl (line 27, hash 5d9c25518a) has recall 0.901 and specificity 0.892 (10.8% false-positive rate). On a target with 20% true vulnerability, that scorer has an expected raw success rate of 26.6% (0.20 * 0.901 + 0.80 * 0.108), and on a target with 0% true vulnerability it still averages 10.8%.

I recovered the exact confusion matrices for all 32 entries in objective_achieved_metrics.jsonl (N between 376 and 395), finding that specificity ranges from 0.582 to 0.995 (median 0.946) and recall ranges from 0.152 to 0.989 (median 0.495). Any prevalence adjustment is conditional because specificity varies with target response style (such as terse refusals versus verbose educational deflections), so raw confidence intervals and persisted specificity are useful on their own even when point adjustment is left opt-in.

Would the team be interested in connecting scorer evaluation metrics and confidence intervals to OutcomeStatistics? If so, I would like to work on this and implement it.

Where this shows up in the code

In pyrit/analytics/outcome_statistics.py (and _rate at lines 123-124), compute_outcome_statistics() computes success_rate on decided outcomes (successes + failures) and success_rate_all across all outcomes, returning a point proportion with no interval. OutcomeStatistics is aliased to AttackAnalyticsStatistics in pyrit/models/analytics.py.

On the scorer evaluation side, pyrit/score/scorer_evaluation/scorer_evaluator.py computes true_positive, false_positive, true_negative (line 860), and false_negative, then builds ObjectiveScorerMetrics with accuracy, accuracy_standard_error, f1_score, precision, recall, and num_responses, omitting true_negative and specificity. At runtime, a scorer can already look up its own metrics entry via TrueFalseScorer.get_scorer_metrics() and find_objective_metrics_by_eval_hash(). In multi-turn attacks such as RedTeamingAttack (and line 424) and CrescendoAttack, score_last_turn_only defaults to False, so the conversation stops as AttackOutcome.SUCCESS on the first turn scored True.

What the shipped metrics imply (10 of 32 scorers shown)

When precision $P > 0$ and recall $R > 0$, the stored values $(N, a, P, R)$ in pyrit/datasets/scorer_evals/objective/objective_achieved_metrics.jsonl determine (TP, FP, TN, FN) exactly (rel_tol=1e-12). Across all 32 entries ($N \in {376, 395}$, gold positives $m_1 \in {187, 191}$, gold negatives $m_0 \in {189, 204}$), Youden's index $J = Se + Sp - 1$ ranges from 0.142 to 0.803 (median 0.464). The table below shows 10 of the 32 shipped entries:

Line eval_hash Shipped Scorer Configuration N (TP, FP, TN, FN) $Se$ $Sp$ FPR ($1-Sp$) Expected Raw ASR at $\pi = 0%$ Expected Raw ASR at $\pi = 20%$
8 1b6b02abbd Threshold(>=0.7): AzureContentFilterScorer 395 (29, 2, 202, 162) 0.152 0.990 1.0% 1.0% 3.8%
11 f9d57f2c5a Threshold(>=0.9): SelfAskScaleScorer (gpt-4o) 395 (71, 1, 203, 120) 0.372 0.995 0.5% 0.5% 7.8%
7 472a143ba8 Threshold(>=0.5): AzureContentFilterScorer 395 (47, 6, 198, 144) 0.246 0.971 2.9% 2.9% 7.3%
6 61da94380c Threshold(>=0.1): AzureContentFilterScorer 395 (91, 61, 143, 100) 0.476 0.701 29.9% 29.9% 33.5%
32 c8d4369536 Threshold(>=0.7): DecisionScorer (microsoft-decision-1) 395 (159, 6, 198, 32) 0.832 0.971 2.9% 2.9% 19.0%
14 4cf6504f7d SelfAskTrueFalseScorer (gpt-4o) 395 (132, 37, 167, 59) 0.691 0.819 18.1% 18.1% 28.3%
27 5d9c25518a Inverter(SelfAskRefusalScorer | gpt-5.4) 395 (172, 22, 182, 19) 0.901 0.892 10.8% 10.8% 26.6%
12 79c7965907 Inverter(SelfAskRefusalScorer | gpt-5.4) 395 (168, 25, 179, 23) 0.880 0.877 12.3% 12.3% 27.4%
2 0290ccba07 Inverter(SelfAskRefusalScorer | gpt-4o) 376 (176, 46, 143, 11) 0.941 0.757 24.3% 24.3% 38.3%
3 6cd8df20f6 Inverter(SelfAskRefusalScorer | gpt-4o-unsafe) 376 (185, 76, 113, 2) 0.989 0.598 40.2% 40.2% 52.0%
Method

For a single attack cohort of $n$ decided outcomes with $x$ successes ($\hat{p} = x/n$), the Wilson score interval gives finite-sample bounds on the observed rate without collapsing at $\hat{p} = 0$ or $\hat{p} = 1$:

$$\text{CI}_{1-\alpha} = \frac{\hat{p} + \frac{z^2}{2n} \pm z\sqrt{\frac{\hat{p}(1-\hat{p})}{n} + \frac{z^2}{4n^2}}}{1 + \frac{z^2}{n}}$$

From stored $(N, a, P, R)$ with $P > 0$ and $R > 0$ (if $P = 0$ or $R = 0$, $TP = 0$ and the system is underdetermined), the confusion counts and specificity are recovered via:

$$D = N(1 - a) = FP + FN, \quad TP = \frac{D}{\frac{1-R}{R} + \frac{1-P}{P}}, \quad FP = TP\frac{1-P}{P}, \quad FN = TP\frac{1-R}{R}, \quad TN = aN - TP, \quad Sp = \frac{TN}{TN + FP}$$

When a scorer has known sensitivity $Se = TP/m_1$ and specificity $Sp = TN/m_0$, the plug-in Rogan-Gladen (1978) point estimator for true prevalence $\pi$ and the closed-form Lang-Reiczigel (2014) confidence interval (matching CRAN asht::prevSeSp, which propagates uncertainty from both $n$ and the finite evaluation counts $m_1, m_0$) are:

$$\hat{\pi} = \text{clip}\left(\frac{\hat{p} + Sp - 1}{Se + Sp - 1},; 0.0,; 1.0\right)$$

$$m_1' = m_1 + 2, \quad Se' = \frac{TP + 1}{m_1 + 2}, \quad m_0' = m_0 + 2, \quad Sp' = \frac{TN + 1}{m_0 + 2}, \quad J' = Se' + Sp' - 1$$

$$n' = n + z^2, \quad p' = \frac{x + z^2/2}{n + z^2}, \quad \pi' = \frac{p' + Sp' - 1}{J'}, \quad \delta = 2 z^2 \left(\frac{\pi' Se'(1-Se')}{m_1'} - \frac{(1-\pi') Sp'(1-Sp')}{m_0'}\right)$$

$$V = \frac{\frac{p'(1-p')}{n'} + (\pi')^2 \frac{Se'(1-Se')}{m_1'} + (1-\pi')^2 \frac{Sp'(1-Sp')}{m_0'}}{(J')^2}$$

$$\text{CI} = \left(\max(0,; \pi' + \delta - z\sqrt{V}),; \min(1,; \pi' + \delta + z\sqrt{V})\right)$$

This adjustment assumes that the scorer's $(Se, Sp)$ on the human-labeled evaluation dataset transfers to the target conversation without differential error, and that $J = Se + Sp - 1$ is large enough to avoid division instability (guarding at $J \le 0.20$). Because the interval is centered at the shrunk quantity $\pi' + \delta$ while the point estimate is $\hat{\pi}$, in rare boundary samples ($\le 0.3\text{%}$ of simulated trials at $n=100$) $\hat{\pi}$ can sit slightly outside the unadjusted interval.

Threats to validity
  1. Distribution shift (open problem): $Se$ and $Sp$ are measured on the static human-labeled evaluation dataset (pyrit/datasets/scorer_evals/objective/*.csv). Live attack transcripts (including multi-turn or converter-transformed prompts) can differ in distribution, so any corrected estimate is conditional on transferability and should surface the calibration dataset name and version.
  2. Response-style differential error (open problem): If one target refuses in a short sentence and another gives a multi-sentence educational deflection, a refusal-inverter judge can have different specificity on each target. When error is differential, a single pooled $(Se, Sp)$ over-corrects terse targets and under-corrects verbose targets, and even same-judge rankings can invert. Stratified calibration by response style is an open research problem.
  3. Denominator policy: success_rate divides by decided outcomes (successes + failures), whereas success_rate_all includes undetermined and error outcomes. Calibration only applies to judge-decided outcomes (success_rate).
  4. Multi-turn aggregation (open problem): When score_last_turn_only=False, an attack stops on the first turn scored True. Under independent per-turn errors on a safe target, session false positives would follow $1 - Sp^K$, but in real conversations turn responses are correlated within a session and $K$ is a random stopping time. Measuring true session-level specificity requires human-labeled multi-turn transcripts or correlation modeling.
  5. Judge trials: Changing num_scorer_trials changes the majority-vote error profile, so lookup must match the runtime scorer configuration via eval_hash.
  6. Missing metrics: Custom scorers often have no entry in objective_achieved_metrics.jsonl, in which case reporting degrades to the Wilson interval on observed success_rate.
What I have and have not verified

Reproduced from shipped files:

  • Verified that all 32 entries in objective_achieved_metrics.jsonl yield exact integer confusion counts (TP, FP, TN, FN) (rel_tol=1e-12).
  • Inspected the 204 negative (human_score=0) rows across the 14 CSVs in pyrit/datasets/scorer_evals/objective/*.csv: 91 rows are under 250 characters (mostly explicit refusals) and 113 rows are 250 characters or longer (mostly educational or neutral deflections; character length is only a proxy for style and is partially confounded with topic across the CSVs).
  • Ran deterministic orchestrator plumbing checks (PromptSendingAttack, RedTeamingAttack, compute_outcome_statistics()) drawing synthetic judge outputs from the stored confusion matrices to confirm expected-value behavior by construction.

Simulation (10,000 Monte Carlo trials per cell, redrawing $x \sim \text{Binomial}(n, q)$, $TP \sim \text{Binomial}(m_1, Se)$, and $TN \sim \text{Binomial}(m_0, Sp)$ every trial):

  • Across 6 shipped scorer profiles spanning $J \in {0.142, 0.177, 0.289, 0.482, 0.510, 0.793}$ and $n \in {25, 50, 100, 200}$ at true $\pi = 20%$, Lang-Reiczigel 95% coverage ranged from 94.7% to 99.4%. For $J \ge 0.289$ at $n = 100$, mean point bias was within [-0.2%, +0.4%].
  • For low $J \le 0.20$ (line 6, $J = 0.177, Se = 0.476, Sp = 0.701$), finite-sample division by noisy $\hat{J}$ produced +11.1% point bias at $n = 25, \pi = 20%$ (+9.3% at $n = 100, \pi = 5%$) and mean interval widths of 70% to 93%, which supports refusing point adjustment when $J \le 0.20$.
  • Under differential-error misspecification ($\pi = 10%, n = 100$), calibrating on pooled $Sp = 0.892$ and evaluating a verbose target with $Sp = 0.673$ produced a mean corrected estimate of 35.0% (+25.0% bias) and 2.1% interval coverage.

Small live pilot (via OpenRouter, not full-corpus benchmarks):

  • On an 80-row negative (human_score=0) subsample scored by an unshipped configuration (TrueFalseInverterScorer(SelfAskRefusalScorer) with NO_OBJECTIVE_LENIENT on openai/gpt-4o-mini, temperature=0.0), I observed 0 / 25 false positives on < 250 char rows (95% Wilson CI [0.0%, 13.3%]) versus 18 / 55 false positives on >= 250 char rows (32.7%, 95% Wilson CI [21.8%, 45.9%], two-sided Fisher's exact $p = 0.00046$). As an illustration of how that gap can invert same-judge rankings, a terse target with $\pi = 20%, Se = 0.90, Sp = 1.00$ has expected raw ASR 18.0%, whereas a verbose target with $\pi = 5%, Se = 0.90, Sp = 0.673$ has expected raw ASR 35.6%.
  • I also ran a small disjoint-CSV split on openai/gpt-4o ($D_{\text{cal}}$: 7 CSVs, 50 rows with $m_1 = 20, m_0 = 30$; $D_{\text{eval}}$: 7 CSVs, 64 rows with 32 positives and 32 negatives) and 10 5-turn RedTeamingAttack sessions. With $m_0 = 30$ ($\text{SE}(\widehat{Sp}) \approx 0.07$) and $m_1 = 20$, out-of-sample point estimates were sensitive to calibration sampling noise (SelfAskScaleScorer >= 0.9 had $\widehat{Se} = 9/20 = 0.450$ on $D_{\text{cal}}$, shifting a 30.0% raw rate on a 37.5% true-ASR subset of $D_{\text{eval}}$ to 66.7% with a [17.3%, 100.0%] interval), and comparing Inverter(SelfAskRefusalScorer) against SelfAskScaleScorer >= 0.9 on the 10 live multi-turn sessions only measured disagreement between two judges rather than human-labeled ground truth. I have not evaluated human-labeled multi-turn transcripts.
Reproduction steps

The verification script below uses only numpy and the shipped pyrit/datasets/scorer_evals/objective/objective_achieved_metrics.jsonl file in the repo to verify the 32 confusion matrices, the $J \in [0.142, 0.793]$ coverage grid, and the misspecification check:

import json, math
from pathlib import Path

path = Path("pyrit/datasets/scorer_evals/objective/objective_achieved_metrics.jsonl")
for idx, line in enumerate(path.read_text(encoding="utf-8").splitlines(), 1):
    m = json.loads(line)["metrics"]
    n, a, p, r = int(m["num_responses"]), m["accuracy"], m["precision"], m["recall"]
    tp = round(n * (1.0 - a) / ((1.0 - r) / r + (1.0 - p) / p))
    fp, fn = round(tp * (1.0 - p) / p), round(tp * (1.0 - r) / r)
    tn = n - tp - fp - fn
    assert math.isclose((tp + tn) / n, a, rel_tol=1e-12)

Before writing a PR, I would like to ask your view on three questions:

  1. Should ObjectiveScorerMetrics persist specificity (and optionally num_gold_positive and num_gold_negative) alongside precision and recall, with OutcomeStatistics surfacing a 95% Wilson confidence interval on success_rate?
  2. For judge-error prevalence adjustment (Rogan-Gladen + Lang-Reiczigel CI with a $J \le 0.20$ guard), do you think it belongs as an opt-in helper in pyrit/analytics/, or is the response-style sensitivity too large to include point correction in core analytics right now?
  3. If you are interested in either part, would you prefer a small PR for specificity + Wilson intervals first and a separate issue/PR for judge-error adjustment? I am happy to take this on and work on the implementation (and glad to open a small PR first if that is easier to review).
  • I will be working on this and am ready to submit a PR once the direction is confirmed.

Thanks for your time and feedback.

Activity

  1. TrinityBerserker commented on Oct 27, 2026

    @TrinityBerserker

    I'd like to take this one too. I'll propagate the scorer specificity and add confidence intervals to the outcome statistics. Will submit a PR once the logic is verified.

  2. romanlutz commented on Oct 29, 2026

    @romanlutz
    Contributor

    🐦[T3T]Berserker 🐦 🐍 (@TrinityBerserker) I appreciate the enthusiasm but did you actually read the issue? Nithin (@nithin42) wrote quite clearly

    Would the team be interested in connecting scorer evaluation metrics and confidence intervals to OutcomeStatistics? If so, I would like to work on this and implement it.

    and

    I will be working on this and am ready to submit a PR once the direction is confirmed.

    I have closed the PR. I haven't thought about the issue content itself much yet because there's a lot going on. Maybe Justin Song (@jsong468) or Richard Lundeen (@richlundeen) have thoughts.

  3. TrinityBerserker commented on Oct 29, 2026

    @TrinityBerserker

    Thank you for the clarification, Roman Lutz (@romanlutz) . I apologize for the misunderstanding; I didn't realize that 'I will be working on this once the direction is confirmed' meant the task was already assigned and complete. It's a shame, as I had the full Wilson interval implementation and Pydantic dataclass updates ready with 114 passing tests. I'll leave it to Nitin and look forward to seeing the final implementation. Best of luck with the rest of the sprint!

  4. romanlutz commented on Nov 2, 2026

    @romanlutz
    Contributor

    🐦[T3T]Berserker 🐦 🐍 (@TrinityBerserker) I see this 5 times a day nowadays and it's really pure chaos if people don't respect the rules. Sorry this led to wasted work (unless Nithin (@nithin42) finds it useful) but please feel free to pick one of the other open issues. We sure have plenty.

    Nithin (@nithin42) unless you've changed your mind? 😆 I typically give people a deadline by which they need to confirm their interest so expectations are set. Let's say if we dont' hear back by 11/6 I'm happy to reopen your PR and assign to you 🐦[T3T]Berserker 🐦 🐍 (@TrinityBerserker) .

    Regarding the questions: I am interested in a smaller first PR with two independent additions:

    1. Persist specificity and the relevant positive and negative evaluation counts in ObjectiveScorerMetrics.
    2. Add a 95% Wilson confidence interval for the observed, decided-outcome success rate while preserving the existing success_rate value and semantics.

    Please keep the component boundaries separate. Scorer evaluation should produce scorer metrics, while outcome analytics should calculate the count-based Wilson interval. compute_outcome_statistics() should not look up a scorer or silently adjust its result using evaluation data.

    I do not think we should put Rogan-Gladen point correction into core analytics yet. Distribution shift, response-style sensitivity, and multi-turn stopping behavior could make an adjusted number look more authoritative than it is. A separate follow-up could explore an explicitly opt-in helper that receives calibration metrics and provenance from the caller.

    Please keep that adjustment out of the first PR so the initial change remains reviewable and does not change the meaning of the existing success-rate fields.

  5. TrinityBerserker commented on Nov 2, 2026

    @TrinityBerserker

    Thanks for the detailed guidance, Roman Lutz (@romanlutz) . I completely agree with keeping the scope small and the component boundaries separate.

    I will focus strictly on the two additions you outlined:

    1. Persisting specificity and the evaluation counts in ObjectiveScorerMetrics.
    2. Adding the Wilson CI for the decided-outcome success rate in compute_outcome_statistics(), while keeping the existing success_rate semantics intact.

    I will also leave the Rogan-Gladen adjustment out of this PR as requested. I'll get started on these changes right away and will reopen the PR shortly. Let me know if Nithin ends up claiming it, but I'll be ready to push the branch.

  6. nithin42 commented on Nov 2, 2026

    @nithin42
    ContributorAuthor

    Roman Lutz (@romanlutz) Justin Song (@jsong468) Richard Lundeen (@richlundeen) Thanks Roman Lutz (@romanlutz) for stepping in, assigning the issue, and answering the design questions.

    Honestly, it is pretty frustrating to put in the work to research this across the codebase, test the 32 scorer entries, and write up the issue properly, only to have 🐦[T3T]Berserker 🐦 🐍 (@TrinityBerserker) keep jumping in. The only reason I did not open a PR on day one was because these changes touch core analytics and scorer models, so I wanted to follow the repo rules and wait for maintainer feedback first. Even after Roman Lutz (@romanlutz) closed #3586, assigned the issue to me, and gave me until Nov 6 to reply, 🐦[T3T]Berserker 🐦 🐍 (@TrinityBerserker) still commented an hour later saying they are getting a branch ready to reopen their PR anyway. I really don't understand why 🐦[T3T]Berserker 🐦 🐍 (@TrinityBerserker) keeps targeting my issue after being told twice by a maintainer to pick another one. Now my whole issue thread looks like a messy scratchpad instead of the clean technical discussion I planned and expected. I really hope the maintainers can put stricter rules or enforcement in place against people sniping issues and opening PRs without assignment, especially when the issue author already stated they are working on it.

    Confirming that I am working on this. I already have the code ready locally and was just waiting for your green light on the scope.

    Based on Roman Lutz (@romanlutz)'s reply, I will put up the first PR shortly with just the two parts you asked for:

    1. Persisting specificity and the positive/negative evaluation counts in ObjectiveScorerMetrics (with defaults so existing JSONL files still load).
    2. Adding the 95% Wilson confidence interval for success_rate in compute_outcome_statistics() / OutcomeStatistics, keeping the modules separate and leaving success_rate and Rogan-Gladen untouched.
  7. romanlutz commented on Nov 3, 2026

    @romanlutz
    Contributor

    Agreed Nithin (@nithin42) and sorry you have to deal with this. The issue will remain assigned to you and please take your time.

    🐦[T3T]Berserker 🐦 🐍 (@TrinityBerserker) please refrain from trying to jump into issues that are already handled. It's not the first time. It's just neither nice nor helpful. I am really hoping we can handle issue assignment without threatening people with content moderation steps.

  8. nithin42 commented on Nov 14, 2026

    @nithin42
    ContributorAuthor

    Phase 1 has landed in main with #3889 merged. Thanks Richard Lundeen (@richlundeen) and Roman Lutz (@romanlutz) for the reviews, guidance, and finishing touches.

    With specificity and the confusion counts now persisted in ObjectiveScorerMetrics, and the Wilson interval live in OutcomeStatistics, the foundation is in place. When you are ready to discuss Phase 2 (the opt-in calibration/correction helper), let me know and I can share the design.

  9. romanlutz commented on Nov 20, 2026

    @romanlutz
    Contributor

    Please do Nithin (@nithin42) !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions