Calculating attack success rate from PyRIT results

Calculating attack success rate from PyRIT results means defining the numerator, the denominator and the handling of undetermined scores and errors before any number leaves the team. This page explains how to do that and how to present the result without overstating it.

On this page

Calculating attack success rate from PyRIT results: what the number means

A security or AI team that has run PyRIT against a model or application now has to turn those results into one number for leadership, an auditor or a customer. The attack success rate (ASR) looks simple, but it is only as good as the definition behind it. PyRIT does not hand you an ASR. It records the conversations, the prompts sent to a target, the responses returned and the scores applied to each attack, and the team decides which of those records count as a success, which count as attempts and how the results are grouped. Before any figure is quoted, the team should write down that definition: which attacks are included, which scorer decides success, how each technique and harm category is grouped, and what happens to results that could not be scored.

The calculation is needed at specific points: before a rollout, to set a baseline; after a model, system prompt, safety filter or routing change, to see whether anything moved; and when someone needs evidence for a review. Each of these uses asks a different question, so the same run may support different numbers. PyRIT's memory stores conversations and results in SQLite or Azure SQL, and its scorers evaluate responses with LLMs, Azure AI Content Safety or custom logic. Those scorer outputs are judgments with their own error, so the reader should confirm, for the scorer the team chose, how it was validated against human labels before its verdicts are treated as a rate.

Teams should confirm three things before they publish a number. First, the denominator: whether attacks that were undetermined, errored or timed out are excluded, counted as failures or reported separately, and whether that choice is stated next to the figure. Second, the scope: the number applies only to the techniques, datasets and targets actually run, and a low rate against one technique says nothing about the others. Third, the comparison: ASR figures from different scorers, PyRIT versions or model versions should not be placed side by side as if they measured the same thing. A figure presented with its definition, its excluded results and its run conditions is far easier to defend than a bare percentage.

Handling undetermined scores and errors in the denominator

Excluding undetermined and errored attacks from the denominator computes the rate only over attacks that produced a usable verdict. The result describes how often the target failed when the scorer could judge it, which can be a flattering picture if the excluded attacks cluster in the cases that were hardest to judge. An errored attack that consistently fails on one technique, for example a multi-turn strategy that times out against a slow endpoint, will vanish from the rate while the technique still looks strong. This treatment fits when the exclusions are few, random in appearance, and reviewed. State the count of excluded attacks next to the rate, and report the exclusion reasons by technique.

  • Hidden concentration: Exclusions tied to one technique or harm category can make that row look safer than it is.
  • Small remaining base: When most attacks are excluded, a single successful attack can swing the rate sharply.
  • Stated count: Print how many attacks were excluded alongside the denominator, not only the final percentage.
  • Reason codes: Group exclusions by cause, such as scorer abstention, target error or timeout.
  • Reviewed sample: Spot-check a sample of excluded attacks to confirm they were not failures in disguise.

Before writing this rule, confirm with the PyRIT documentation for your installed version how errored and unscored attacks are recorded in memory, since the exclusion query depends on that record.

Steps to calculate ASR by technique and harm category

This sequence turns raw PyRIT attack results into an attack success rate for each technique and harm category pair, with the counts shown beside every rate so reviewers can judge how much weight each number can carry.

  1. Confirm the run scope and labels

    Before pulling any data, the engineer records which runs belong to the comparison: the target model or application version, the prompt or configuration version, the date range and the label values used for engagement, operator and build. Every compared group must use the same run labels so that differences reflect the variable under test and not a change in how runs were tagged. The step is done when the list of run identifiers and labels is written down and a reviewer can reproduce the selection from it.

  2. Pull attack results from memory

    The engineer retrieves attack results for the selected runs using the async memory API, or reads the scenario results for scenario-based runs. Each record should carry the attack technique, the harm category or objective, the final score or scorer outcome, and any error status. Store the raw pull as a file so later counts can be traced back to the source rows. The step is done when the row count matches the number of attacks the run log reports as launched.

  3. Apply the written counting rule

    Before computing any ratio, the team writes down the counting rule in plain terms: which scorer outcomes count as a successful attack, which count as a failed attack, and how undetermined scores and errors are handled. The rule is applied to every row in the same way across all groups. Reviewers should be able to see the rule next to the results. The step is done when each row has exactly one classification (success, failure, undetermined or error) recorded in a column.

  4. Group results by technique and harm category

    The engineer groups the classified rows by attack technique and by harm category, producing one group for each pair. Groups with very few attacks should be flagged rather than dropped, because a single attack can swing a rate sharply. The step is done when the grouping table lists every technique and harm category that appears in the pull, with no rows left unassigned.

  5. Compute the ratio and record the counts

    For each group, the engineer computes the attack success rate as successful attacks divided by the chosen denominator under the written rule, and writes the numerator, denominator, undetermined count and error count beside the rate in the same table row. Rates without their counts should never appear in a summary. The step is done when every group has a rate and its supporting counts in one row.

  6. Reconcile totals and error counts

    The engineer checks that, within each group, successes, failures, undetermined results and errors add up to the number of attacks launched for that group, and that the grand total matches the run log. Any mismatch is traced to a missing row, a duplicated record or an unhandled status before the table is used. The step is done when the reconciliation check passes and the undetermined and error counts appear in the final output rather than being absorbed silently into the denominator.

  7. Review the table before sharing

    A second person reviews the grouped table against the counting rule and the run labels, checking that compared groups share the same labels and that small groups carry a caution in the write-up. They also confirm that the table states the scorer used and the date of the run. The step is done when the reviewer signs off on the reproducible table and its caveats, and the file is saved with the run identifiers it was built from.

How ASR gets overstated and how to prevent it

An attack success rate is only as trustworthy as the counts behind it. The risks below share one root cause: the number looks precise while the group sizes, denominators, scorer accuracy or run conditions behind it are weak or unknown. Check each one before a rate goes into a findings report.

Small sample sizes per group

A rate computed from a handful of attacks in one technique or harm category can swing sharply with a single result. Before reporting a percentage for a group, record the raw counts of successes and attempts next to it. Ask whether the group is large enough to support the comparison you are making, and say so plainly when it is not. Treat small groups as directional signals to retest rather than settled findings.

A changing denominator between runs

If one run counts errored or undetermined attacks in the denominator and the next run drops them, the two rates measure different things. Fix a single denominator rule before the first run and apply it to every comparison. Write the rule into the report so a reader can see whether errors lowered or raised the rate, and keep the raw counts for each status.

Scorer error that was never measured

ASR depends on a scorer deciding which responses count as successful, and that scorer can misjudge. A rate built on an unvalidated judge carries an error that never appears in the number. Sample responses the scorer labeled, review them by hand, and record how often the scorer agreed with your reviewers. Report that agreement alongside the rate so readers know how far to trust it.

Comparing runs across different targets

A lower ASR on one run means little if the target model, system prompt, converters or attack settings changed between runs. Record the target version, configuration and attack set with every run and compare only runs that match on those fields. When something did change, say that the difference may come from the change, not from the model's safety alone.

Averaging rates across unequal categories

An overall ASR that averages category rates gives a 20-attack category the same weight as a 500-attack category. The overall figure then reflects the category layout more than the target's behavior. Compute the overall rate from pooled counts, and show the per-category rates with their counts. If you average anyway, state the weighting so no reader mistakes it for a pooled rate.

How attack results become a reported ASR

The flow starts with PyRIT attacks sending prompts to a target, with scorers writing a verdict for each response into memory. A query or scenario history step then groups those results by technique and harm category. The counting rule separates successes from failures, sends undetermined and errored attempts to their own counts, and produces a table where every rate sits beside its numerator and denominator. Check that the denominator matches the attempts you intended to count before you quote any rate.

Flow from PyRIT attack results in memory to a reported ASR table.

Counting options and when each fits

This table compares three ways to handle undetermined and errored results in the denominator, plus the grouping keys that split the ASR by technique, harm category, target version and label. Read each row for what the number measures and what it hides, then pick the combination that matches the question your reviewers are asking. Confirm the exact result and label field names in your installed PyRIT version before writing a query.

OptionWhat it measuresWhat it hidesWhen it fits
Exclude undetermined from the denominatorSuccess rate among objectives the scorer could judgeHow often the scorer gave up, which can flatter the target if failures cluster on hard casesEarly triage, when you also report the undetermined count next to the rate
Count undetermined as not successfulA conservative floor on attacks that clearly succeededScorer uncertainty, so a low rate may reflect weak scoring rather than a robust targetCompliance-facing summaries where a claimed low ASR must hold up under review
Report undetermined and errors separatelyJudged success rate alongside explicit counts of undetermined and failed runsLittle, but it adds numbers a reader must interpret togetherEvidence packs and reviews that will ask how many attacks were never judged
Group by techniqueWhich attack strategy, such as single-turn, Crescendo or TAP, succeeds most oftenDifferences in objectives and seed prompts across techniquesChoosing which attack strategies to keep in a recurring test suite
Group by harm categoryWhich harm areas the target is most exposed toTechnique mix inside each category, so small categories can swing widelyMapping results to the risk areas your policy or regulator names
Group by target versionChange in ASR between model, prompt or configuration versionsChanges in scorer, seed set or converter settings between runsRegression checks, provided the scorer and objectives stay fixed across versions
Group by labelASR for one engagement, operator or build, as tagged at run timeRuns that were missing or inconsistent labels, which drop out silentlySeparating engagements or teams that share one memory database

Setting up a repeatable ASR report from PyRIT memory

This sequence gives a team a fixed environment, a labeled record of every run, and a written counting rule so that the attack success rate they report can be reproduced by someone else. The result is a script that reads PyRIT memory and has been checked against results whose answers are already known.

  1. Install PyRIT on a supported Python version

    The engineer responsible for the report creates a dedicated virtual environment and installs PyRIT from PyPI with pip. The PyPI package supports Python 3.10 up to but not including 3.15, and the PyRIT documentation recommends Python 3.13, so the team should pin that minor version in its environment. Record the exact PyRIT version and Python version in the repository. The step is done when the import succeeds in a fresh environment and the recorded versions match what was installed.

  2. Point memory at a chosen database

    Configure PyRIT memory to use SQLite for a single-operator setup or Azure SQL where the team shares results. Confirm which database file or server holds the records before any run starts, because a report that reads a different store than the one written to will silently miss results. Keep the database location in configuration, not in the counting script. The step is done when a test run writes a conversation and score to the chosen store and a read query returns that same record.

  3. Confirm credential and settings locations

    Check that PyRIT reads credentials from the documented location, the ~/.pyrit/.env file, and settings from ~/.pyrit/.pyrit_conf. Ask the team to confirm that no key is hard-coded in the report script and that each operator's machine resolves the same settings. Note any difference between operators, since differing target or scorer configuration changes what the scores mean. The step is done when a short diagnostic prints the resolved target and scorer names and the same output appears on every operator's machine.

  4. Tag every run with labels

    Attach labels to each run for the engagement, the operator, the target model or application version, and the build identifier, using the same label names every time. Without these labels, a later query cannot separate results from different model versions or different people, and the ASR figure may mix them. Agree the label keys and allowed values in writing before the first run. The step is done when a sample query can group stored attack results by each label and the counts add up to the number of runs executed.

  5. Write the counting rule before the first run

    Before any results are collected, the team writes the counting rule into the repository as a short document and as the code that implements it. The rule states the numerator (attacks scored as a successful attack), the denominator (attacks with a determined score, or all attacks if the team chooses to count errors), how undetermined scores and errors are handled, and how results are grouped by technique and harm category. Ask a second reviewer to confirm that the rule matches the report template. The step is done when the rule is committed and the reviewer's sign-off is recorded in the same change.

  6. Build the report query and grouping

    Write the script that reads attack results from memory, applies the counting rule, and produces a table with one row per technique and harm category. The table should show the numerator, the denominator, the number of undetermined or errored attacks excluded or included under the rule, and the resulting rate. Keep the rate calculation in a single function so the same logic is used everywhere the figure appears. The step is done when the script runs end to end against a real database file and produces a table with every group present.

  7. Verify the script against known results

    Create a small, hand-checked set of attack results in a separate test database, where each result has a known outcome, including at least one undetermined score and one error. Run the report script against this set and compare every count and rate with the values worked out by hand. Any mismatch means the counting logic or the query is wrong, and the team should fix it before the script touches real engagement data. The step is done when every expected figure matches exactly and the test set and expected output are saved in the repository for future reruns.

  8. Rerun and archive the report

    For each reporting cycle, rerun the same script against the labeled memory store and save the output with the PyRIT version, label values, and counting rule version attached. Compare the new table with the previous one and check that any change in a rate can be traced to new runs or a changed target rather than to a change in the script. Ask the reviewer to confirm the archived output matches a rerun. The step is done when a second run from the archived configuration reproduces the saved table exactly.

Security and data handling for results that contain harmful outputs

Attack success rate work produces transcripts of harmful model output, so the results are sensitive data in their own right. The cards below cover who can reach the memory and exports, how to redact before sharing, how long records live, how credentials are stored, and how to report flaws in PyRIT itself.

Restrict access to the memory database

PyRIT memory stores conversations, scores and attack results in SQLite or Azure SQL, so the database holds the full harmful output behind every ASR figure, not just the summary. Decide who can read the file or database before the first run, and keep operators who only need counts away from raw conversation tables. Check file permissions on local SQLite files and the database role assignments on Azure SQL, and confirm that backups inherit the same restrictions.

PyRIT documentation

Redact before sharing exports

A rate in a slide tells a reviewer little without the transcript that supports it, but the transcript is often the harmful content itself. Plan a redaction step for any export that leaves the red team, such as a finding summary sent to a product owner. Remove or blur model output that is not needed to confirm the finding, and keep an unredacted copy only in the controlled store. Test that redaction actually removes the content, not just the visible text.

Set a retention period for attack records

Decide how long conversations, scores and run labels are kept, and whether that period matches your engagement terms and any compliance evidence requirement. Retention should be a written decision, not the default of whatever storage was used. Ask whether deleting memory entries also removes derived exports and reports, and record the deletion step in the engagement close-out so old harmful outputs do not persist indefinitely.

Keep credentials out of shared files

PyRIT reads credentials from ~/.pyrit/.env and settings from ~/.pyrit/.pyrit_conf. These files hold API keys for the target and scorer models, which can incur cost and grant access beyond the test. Keep them in each operator's home directory with restricted permissions, never in the repository or in exported results, and rotate keys after an engagement. For shared environments, confirm with your platform team whether a managed secret store is a better fit than a plain file.

Scope scorer and judge model access

Scorers that use LLMs send the harmful response to a second model, so the judge endpoint also receives sensitive content. Confirm where that model runs, what its provider logs and retains, and whether your data handling terms allow that transfer. A judge in your own infrastructure or an approved provider keeps the transcript inside your boundary. Record which scorer and model version produced each score, since that affects what the ASR figure means.

Report PyRIT vulnerabilities privately

If testing reveals a flaw in PyRIT itself, such as an issue that exposes stored conversations or credentials, do not open a public issue with exploit details. Vulnerabilities are reported privately through the Microsoft Security Response Center under the project's security policy. Keep the affected transcripts within the restricted store while the report is open, and confirm the current policy in the project README before reporting.

PyRIT README

Questions teams ask before calculating ASR with PyRIT

Can our team calculate attack success rate from PyRIT memory without outside help?

Yes, if you have an engineer comfortable with Python and the async memory API, and if your attacks were tagged consistently from the start. PyRIT stores conversations, prompts, responses and scores in memory (SQLite or Azure SQL), so the raw inputs for ASR already exist. The harder parts are agreeing on what counts as a success, deciding how undetermined scores and errors enter the denominator, and writing the calculation so another person can reproduce it. Teams that skip those decisions often get a number that changes between reruns. Outside help is most useful when the first calculation will be reviewed by auditors, customers or a board.

What makes an ASR engagement larger or smaller?

Effort follows the number of combinations you must report on. The main drivers are:

  • The number of targets, model versions and system prompts under test
  • The number of attack techniques and their multi-turn depth
  • The number of harm categories and the scoring method for each
  • How much scorer work is needed, including calibration against human labels and disagreement review
  • The reporting requirements, such as per-technique tables, confidence context or evidence exports for reviewers

Each added target multiplies the run matrix, and each new scorer adds validation work. Ask any provider to break its quote down along these lines so you can see which driver is adding cost.

How long does setup take before the first ASR number?

Setup time depends mainly on your environment and how much of it is ready. A team with a working Python environment, an accessible test endpoint and an agreed harm taxonomy can start quickly. Setup takes longer when credentials must come from a secrets store, when the target sits behind SSO or a custom HTTP or WebSocket interface, when scoring relies on Azure AI Content Safety or a custom judge, or when the team must first agree on labels and run tagging. Confirm with the provider which of these apply to your environment before accepting a schedule. No fixed duration applies to every setup.

What do we need to provide for an ASR calculation?

You need to provide access and decisions that only your organization can give:

  • A test target with a documented endpoint, a test account and an agreed scope of what may be sent to it
  • Memory storage that the engineers can reach, with retention rules for prompts and responses that may contain sensitive content
  • A named reviewer who resolves scorer disagreements and signs off on what counts as a success
  • The harm categories and attack list that the results must cover

Without a reviewer, disputed scores tend to stay undetermined, which weakens the rate and makes the report harder to defend.

Is one overall ASR number enough for a risk review?

Usually not. A single figure hides the spread across techniques and harm categories, and a low overall rate can conceal a high rate for one serious harm. Report the rate per technique and per harm category, state the number of attempts behind each rate, and show how many results were undetermined or errored instead of scoring them. Present the overall figure only with that context. Note that ASR depends on the prompts, scorer, target version and settings used, so a figure from one run describes that run, not the system in general.

How does DeployOpen scope a fixed-scope ASR reporting engagement?

DeployOpen works from a written scope agreed before work starts. The scope lists the targets, techniques, harm categories, scoring method, reporting format and the evidence delivered with the report. Most engagements are fixed-scope, so deliverables and timelines are set in writing and a quote follows from that scope. DeployOpen sets up PyRIT in your infrastructure, runs the agreed attacks, calculates the rates with the denominator rules you approve and prepares the report. It does not issue audit reports or certifications. Ongoing reruns after model or prompt changes can be covered by a retainer.

Does DeployOpen test the AI system itself or only calculate the numbers?

DeployOpen runs the testing and the calculation together, since an ASR figure is only as good as the attacks and scores behind it. DeployOpen performs security testing of AI systems and agents, including prompt injection, tool and file permissions, data exposure and credential handling, and it can deliver a findings report with fixes and a retest. The ASR calculation is one output of that work. If you only need the rate from runs you already completed, confirm during scoping that your memory records, labels and scorer outputs are complete enough to support it.

How DeployOpen scopes and delivers PyRIT results reporting

DeployOpen treats attack success rate as a reporting deliverable tied to a specific PyRIT run, scorer and denominator rule. We scope the calculation, build the reporting from the memory records your team's runs produce, and hand over a method your reviewers can check and repeat.

How we scope

  • Engagements are fixed-scope, with the ASR definitions, technique and harm groupings agreed in writing before work starts.
  • The written scope fixes how undetermined scores and errors are counted in the denominator and how they are reported.
  • We confirm which PyRIT version, scorers and memory backend (SQLite or Azure SQL) produce the results being measured.
  • Ongoing support and repeat measurement across model or prompt versions can be added as a retainer.

How we build

  • We build a calculation script or report that reads attack results from PyRIT memory grouped by technique and harm category.
  • Each figure is traceable to the attack, conversation and score records behind it, so a reviewer can drill down.
  • We test the calculation against a small set of hand-checked conversations, including undetermined and errored attacks.
  • Reports show the denominator, the count of excluded attempts and the scorer used alongside each rate.

How we hand over

  • You receive the calculation code, the written method, and a sample report that uses your own labels and run identifiers.
  • The documentation states the denominator rule, the scorer dependency and the limits of what the rate can and cannot show.
  • We walk your security and AI teams through the method so they can reproduce a figure and question its inputs.
  • Handover covers how to rerun the calculation after a new PyRIT release or a change to scorer configuration.

How we support

  • Support can cover updates when PyRIT releases change result fields, scorer outputs or memory schemas.
  • Retainers can include repeat runs, retesting after fixes and reviews of how ASR is worded for auditors or customers.
  • Questions to confirm before work starts include which harm categories matter, which scorer your team trusts and who signs off on the figures.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.