PAIR jailbreak attacks in PyRIT

PyRIT's PAIR attack uses an adversarial model to refine one jailbreak prompt over iterations. This page explains how it works, how it relates to TAP, and when it is the cheaper choice to run.

On this page

When PyRIT's PAIR attack is the right jailbreak test

A security or AI platform team needs PAIR when it must know whether a deployed model holds up under iterative jailbreak refinement, where an adversarial model rewrites one jailbreak prompt over successive rounds based on the target's responses. PAIR is a single-prompt refinement attack in PyRIT, added in v0.14.0 as an alias of TAP with PAIR-style defaults, so the same engine runs with settings that match the original PAIR method. Teams reach for it when a model passed static jailbreak sets and the question is whether a persistent, adaptive attacker can wear down the refusal over a few iterations.

PAIR is the lighter choice when the goal is a repeatable signal at modest cost. It keeps one candidate prompt in play rather than a branching tree, so the number of target and adversarial model calls per objective is easier to forecast and cap. Before choosing it, confirm with your PyRIT release notes that the alias defaults still match the behavior you expect, and record the adversarial model, scorer and iteration limit so the result can be reproduced. Check how your target handles conversation state, because a stateless endpoint receives each refinement without the earlier turns that shaped it.

PAIR does not cover everything a broader test should. It does not search widely across prompt variants the way a branching attack does, so a clean PAIR result does not show that the model resists other jailbreak families. It also does not test multi-turn escalation, cross-domain injection through documents or tools, or output filters that only inspect whole responses. Treat PAIR as one test in a suite, and pair it with a gradual multi-turn attack and with checks on the application around the model, which the sibling pages on Crescendo, TAP and XPIA describe.

PAIR configuration options and when each fits

This table compares the choices that shape a PAIR run in PyRIT: the adversarial model, the target type, the objective and scorer, the iteration limit and the memory backend. Read each row as a decision with a cost or coverage consequence, and confirm current defaults in the PyRIT documentation for the version you install.

ChoiceWhen it fitsWhat it changes in cost or coverage
Adversarial modelChoose a model your team is permitted to use for generating attack prompts, and one that will engage with red teaming instructionsEach iteration calls the adversarial model, so its pricing, latency and rate limits set the run's cost and duration; a weaker attacker may stop early without finding a weakness
Target type: stateless endpointUse when each request is independent, such as a single completion API with no session historyPAIR must resend the full context it builds, so requests stay self-contained and results are easier to reproduce, but the target never sees a long conversation
Target type: stateful endpointUse when the application keeps conversation history, such as a chat product with memory or session stateAttacks reach the state the product actually builds, which can expose more behavior, but runs are harder to reproduce and need care with session resets between attempts
Objective and scorerWrite one specific, testable objective per run, scored by an LLM judge, a content safety service or custom logicA vague objective produces unclear scores and wasted iterations; a stricter scorer lowers false positives but may miss partial leaks, so review scorer output on sample conversations
Iteration limitSet a low limit for a quick check of a deployment and a higher limit when earlier runs show the attacker is making progressEach added iteration adds target and adversarial model calls, so cost grows roughly with the limit; confirm the default and whether the run stops on first success in the documentation for your version
Branching compared with TAPChoose PAIR for a single refining prompt chain; choose TAP when you want several candidate branches explored at each stepPAIR spends its budget on one line of refinement, which is usually cheaper per run; TAP branches and prunes, which increases calls per iteration and can widen coverage
Memory backend: SQLiteUse for local runs, individual testing and short evaluations on one workstationLow setup effort and no separate service, but results are tied to one machine and are harder to share across a team
Memory backend: Azure SQLUse when several people or pipelines must share results, or when evidence needs central retentionAdds database setup, access control and recurring hosting cost, but gives one record of attempts that reviewers can query

PAIR versus TAP: how to choose between them

PAIR in PyRIT is an alias of TAP with defaults that match the original PAIR method, so the choice is less about two engines and more about how you configure one search. The cards below cover the decision points that change cost, coverage and the target requirements. Confirm every parameter against the v0.14.0 release notes and the current code before you plan a run.

Search breadth and branching

PAIR's defaults keep one candidate line of attack and refine it over iterations, while TAP is built to branch several candidates per level. Ask your team whether you need depth on one objective or coverage of several phrasings. Confirm the branching and width settings in the current code, because a broader search multiplies target calls on every level.

PAIRAttack added
v0.14.0
v0.14.0 release notes

Pruning and early stopping

Pruning removes weak branches so the search spends its budget on promising prompts. With PAIR-style defaults, pruning is lighter or absent, so a run can consume more target calls on dead ends. Check how the scorer threshold and the pruning settings interact, and set a maximum number of iterations so a failed objective has a clear stopping point.

Cost per objective

Cost is driven by adversarial model calls, target calls and scorer calls, multiplied by iterations and branches. A single-line PAIR-style search usually costs less per objective than a branched TAP search with the same iteration limit. Ask your provider to estimate calls per objective from the configured parameters, and budget for the adversarial and scoring models separately from the target.

Image and multimodal support

TAP documents image support, so check whether the attack configuration you plan to use handles image inputs and outputs before you pick an approach for a multimodal target. Do not assume that a PAIR configuration inherits every capability of TAP. Test one known objective end to end on the exact target type and modality you need.

Target statefulness

PAIR refines a prompt across turns, so it relies on the target keeping conversation context or on the attack resending history. Stateless endpoints that drop context can break the refinement loop and produce misleading results. Confirm how your target stores conversations, and test whether refinements reach the model in the way the attack expects.

Intent and reporting

Choose PAIR when your question is whether a single well-refined jailbreak can defeat the target, and choose TAP when you want to see how a wider search explores the space. Record which configuration you used in your results so that a PAIR run is not reported as a TAP coverage result. Confirm the configuration details with the current PyRIT documentation before you cite results.

Setting up a PAIR run in PyRIT

This sequence takes a team from a clean Python environment to a verified PAIR pilot whose results sit in PyRIT memory. Each step ends with a check, so a failure is caught at the point where it occurs rather than during a full run.

  1. Install PyRIT on a supported Python version

    Create a dedicated virtual environment and install the pyrit package from PyPI with pip. The PyPI package supports Python 3.10 up to but not including 3.15, and the documentation recommends Python 3.13, so confirm your interpreter version before installing. Done means pip show pyrit reports an installed version and python -c "import pyrit" runs without error from the same environment. Check the current release notes on the project's GitHub releases page before pinning a version.

  2. Configure credentials in the .pyrit environment file

    Create ~/.pyrit/.env and add the API keys and endpoints for both the target and the adversarial model. Keep this file out of source control and restrict its file permissions to the account that runs the tests. Confirm the variable names against the PyRIT documentation for your chosen model provider. Done means the file exists, is readable only by the test account, and a short script can read each key without printing its value.

  3. Set run defaults in the pyrit configuration file

    Create ~/.pyrit/.pyrit_conf to hold the settings that should not change between runs, such as the memory database location and default model references. Keep secrets out of this file and place them in the .env file from the previous step. Done means a fresh Python session loads the configuration and reports the memory location you set, which you can confirm by printing the active settings.

  4. Define the target and the adversarial model

    Declare two separate chat targets in your attack script: the system under test, and the adversarial model that refines prompts across iterations. Use a different model family for the adversary where possible so the attacker's behavior does not mirror the target's. Send a harmless greeting to the target and to the adversary and confirm each returns text. Done means both endpoints respond, and you have recorded which model version each one is.

  5. Write the objective and the scorer

    Write a narrow, testable objective that describes one behavior the target should refuse, and choose a scorer that returns a verdict on whether the response meets it. Scorers can be LLM-based, Azure AI Content Safety, or custom logic, so pick the one whose judgments your reviewers can check. Verify the scorer on a known prompt: a clearly harmful response should score as a success and a clear refusal should not. Done means both test cases return the verdicts you expect.

  6. Run a small PAIR pilot

    Construct the PAIRAttack with the target, adversary, objective and scorer, and cap the iteration count low for the first run. Introduced in PyRIT v0.14.0 as an alias of TAP with PAIR-specific defaults, PAIRAttack is the single-prompt refinement form, so confirm its defaults in the current documentation before relying on them. Run one objective with one attempt. Done means the run completes without exceptions and returns a result object for the objective.

  7. Review the pilot results in memory

    Open the conversation history that PyRIT stored in its memory, which uses SQLite by default or Azure SQL where configured. Check each iteration's refined prompt, the target's reply, and the score assigned to it. Confirm that the final verdict matches what you read in the transcript. Done means you can trace every iteration from prompt to verdict and have noted any scorer disagreement before scaling the run.

How the PAIR loop moves between attacker, target and scorer

The loop starts with the objective given to the adversarial model, which writes one candidate jailbreak prompt. That prompt goes to the target under test, and the target's response goes to a scorer. The score and feedback return to the adversarial model, which refines the same prompt for the next iteration until the scorer reports success or the iteration limit is reached. Check that the adversarial model, the target and the scorer are separate roles you have configured, and that every turn is written to memory so each iteration can be audited.

The PAIR refinement loop, with the stop condition and the memory store where each turn is recorded.

Security and operational risks when running PAIR

A PAIR run touches several places where sensitive material can leak or where costs and load can get out of hand: configuration files, stored conversations, the hosted adversarial model and the target itself. The cards below cover what PyRIT documents for each area and what your team should confirm in its own environment before running PAIR against a production system.

Credentials in environment files

PyRIT reads credentials from ~/.pyrit/.env and settings from ~/.pyrit/.pyrit_conf. PAIR needs keys for both the adversarial model and the target, so one file on a shared runner can expose both. Confirm who can read that file, whether it is kept out of source control and images, and whether separate keys are issued per model and per test team.

PyRIT documentation

Stored prompts and responses

PyRIT memory records conversations and results in SQLite or Azure SQL. A PAIR run stores every refined jailbreak prompt and every target reply, including the harmful ones that succeeded. Treat the memory database as sensitive data, set its file permissions or database roles, and decide the retention period with your security team before the first run.

Objectives sent to a hosted model

The adversarial model writes new attack prompts from your objective, and a hosted provider will process that text under its own terms. For regulated data or internal system details, the objective and target description may be sensitive in themselves. Confirm the provider's data handling terms for the adversarial model and choose a locally hosted model where those terms do not fit.

Request volume against the target

PAIR sends many iterations of requests to the target, and each iteration depends on the target's previous reply. Without limits, a run can drive load on a production endpoint, trigger provider throttling or consume paid quota quickly. Set rate limits and a maximum iteration count in PyRIT configuration and agree the test window with the team that owns the endpoint.

Harmful output in logs and exports

Successful PAIR runs produce jailbreak text that could be reused against your system or misused elsewhere. Logs, exported conversations and shared reports can carry that text into tickets, chat channels and email. Limit who can export results, redact harmful content in shared reports, and set a rule for how findings are handed to engineering.

Questions buyers ask about PAIR in PyRIT

What drives the cost of a PAIR run in PyRIT?

The main cost is model calls. Each PAIR run makes calls to an adversarial model that writes and refines the jailbreak prompt, a target model that responds, and a scorer that judges each response. Cost rises with the number of iterations, the number of objectives, and the price of the models behind each role. Because the adversarial and scorer models are often larger hosted models, their per-call charges usually dominate. Ask your team or a partner to estimate calls per objective from the iteration limit you plan to use, then multiply by the objective count and each provider's published rates. Model costs are recurring each time you rerun the suite, so set iteration and objective limits in writing before testing starts.

How long do setup and a first PAIR run take?

Setup time depends on how many pieces are new to your team: a Python environment with PyRIT installed, credentials for the adversarial, target and scorer models, a working connection to the system under test, and agreed objectives with a scoring rule. PyRIT installs with pip and supports Python 3.10 up to but not including 3.15, with the documentation recommending Python 3.13, so the environment itself is usually the quick part. Access approvals and building a reliable target connector are the usual delays. A first run on a small set of objectives shows whether the connector, scorer and memory settings behave before you scale up. Confirm your own timeline against your access and change-control process, since no general duration applies.

What must our team provide before a PAIR attack can run?

Your team needs to provide four things before a PAIR attack can produce useful results:

  • Target access: an endpoint or application you are authorized to test, with a documented way to send prompts and read responses.
  • Objectives: the specific behaviors you want the attack to elicit, written so that success is clear.
  • Scorer criteria: the rule that decides whether a response counts as a successful jailbreak, whether an LLM judge, a content safety service or custom logic.
  • Model accounts: credentials for the adversarial model and the scorer, stored in the locations PyRIT reads, such as ~/.pyrit/.env.

Also confirm who approves testing against production systems and where results are stored. Missing scorer criteria are the most common reason a run produces numbers nobody can interpret.

Can an internal team run PAIR in PyRIT alone?

Yes, if the team has Python experience, can manage model credentials, and can write or adapt a target connector. PyRIT is an open-source framework, so there is no license fee to pay, and the team controls the test code and the data it produces. The harder parts are the ones outside the framework: defining objectives that match your risk model, choosing a scorer you can defend, interpreting results, and keeping the setup current across PyRIT releases. Teams without security testing experience often benefit from an outside review of their objectives and scorer before they rely on the results. DeployOpen can plan and run this work as a fixed-scope engagement inside your infrastructure if you prefer a partner for part of it.

When is PAIR cheaper than TAP or Crescendo?

PAIR is usually the lower-cost choice when you want a single refined jailbreak attempt per objective rather than a broad search. PAIR was added in PyRIT v0.14.0 as an alias of TAP with PAIR-definitional defaults, so the two share an engine but are configured differently. TAP branches and prunes many candidate prompts at each level, which multiplies model calls, so it costs more per objective. Crescendo runs a multi-turn escalation that also consumes calls on every turn. PAIR's cost is driven mainly by its iteration limit, so it suits a quick check on many objectives, or a first pass before a costlier attack. Compare the exact settings in the PyRIT v0.14.0 release notes and your planned call counts before deciding.

What should we confirm about PAIR's settings and target behavior?

Check which defaults your PyRIT version uses for PAIR, including the iteration limit, the adversarial model and the scorer, because these determine both results and cost. Confirm whether your target is stateful, keeping conversation history on its side, or stateless, which changes how each iteration must send context. Also confirm how your target handles rate limits and errors, since retries add model calls. Review the PyRIT documentation for the version you run, and test the configuration on a few objectives before a full run. Record every setting used, so results can be reproduced when the target or the framework changes.

Does PAIR testing carry risks for the systems we test?

The main risks are operational rather than architectural. PAIR sends many adversarial prompts to a target, so it can trigger rate limits, consume quota, create logs that contain sensitive test content, and in some systems produce outputs that reach real users if the target is live. Run tests against a staging or isolated environment where possible, agree on request volume limits with the owners of the target, and set a clear rule for who can read stored conversations. PyRIT stores conversations and results in SQLite or Azure SQL, so decide where that memory lives and how long it is kept before testing begins.

Where PAIR fits in a wider AI red teaming program

PAIR is one attack in a wider program, not a complete assessment. Treat a PAIR run as a fast, narrow probe of whether a single jailbreak objective can be reached through iterative refinement of one prompt. A PAIR result tells you where to look next. If the adversarial model reaches the objective quickly, that suggests the target's single-turn defences are weak for that harm category and deserves a broader search with TAP, which explores several branches in parallel, or a conversational attack such as Crescendo, which tests whether the model's safeguards erode across turns. If PAIR fails across all objectives, that is a weaker signal: it may reflect a strong target, an adversarial model that could not produce useful refinements, or a scorer that did not recognize partial success. Confirm which of these explanations holds before you cut the attack set.

Turn each PAIR result into a finding with the evidence an engineer can reproduce. Record the objective, the target configuration, the adversarial model and its version, the number of iterations, the prompt that succeeded, the full conversation from PyRIT memory, and the scorer output with its rationale. A finding should state the harm category, the target surface it was reached through, and the severity your own policy assigns. Keep the failed runs too, because they show the search effort behind a negative result. Retest after each fix by rerunning the same objective and scorer against the changed system prompt, filter, model version or routing rule, and confirm the change with a fresh run rather than assuming the earlier success is gone.

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.