Tree of Attacks with Pruning (TAP) in PyRIT

How PyRIT's TAP attack branches and prunes adversarial prompts, what its branching factor costs, and what stateful and stateless targets need before you run it.

On this page

When the TAP attack in PyRIT is worth running

If a single jailbreak prompt tells you little about how a model holds up, you need broader coverage than one hand-written attempt gives you. TAP, or Tree of Attacks with Pruning, is PyRIT's option for that breadth. It is a multi-turn search: an attacker model generates several candidate adversarial prompts, the target responses are scored, weak branches are pruned, and the strongest branches are expanded again over successive rounds. The PyRIT documentation describes this branching search as slower and more expensive than lighter techniques, so the question is not whether TAP finds more paths, but whether your test plan needs that extra search before you pay for it.

Within PyRIT's attack strategies, TAP sits at the wide-search end. A single-turn prompt or a scripted multi-prompt sequence is cheap and repeatable, and it suits regression tests of known jailbreaks. Crescendo and PAIR follow one escalating conversation or one refined prompt, which narrows the search. TAP is the choice when you do not yet know which framing will work against a deployment and want the attack to explore several framings in parallel. Before committing, confirm the cost drivers with your team: the adversarial model's compute or API usage, the number of branches and rounds you configure, and the scorer calls made for every candidate response.

A useful decision test is whether you can state what a TAP run would add. If the answer is a broader search across framings for an application you have not tested before, TAP earns its cost. If the goal is a quick check that a known jailbreak is still blocked after a system prompt change, a cheaper attack is the better first run, and TAP can follow if that check fails. Record the configuration you used for each run, since branch count and round limits change both the spend and the result you can defend in a report.

How TAP branches, scores and prunes candidate prompts

The search starts with the objective and the adversarial model, which proposes candidate prompts as branches. Each branch goes to the target, whose response is returned to the scorer, which rates how close the branch came to the objective. Branches scoring below the pruning threshold are dropped, and the surviving ones seed the next round. Check the limits that stop the search, because they set how much the search costs.

TAP loop showing the adversarial model, target and scorer as separate components.

TAP configuration options and when each fits

This table compares the settings a team chooses when configuring a TAP run in PyRIT, with the situations where each fits and how it moves runtime and call volume. Read it before fixing a configuration, because branching and depth multiply the requests sent to both the adversarial model and the target. The main takeaway is that TAP's search cost grows with every setting that widens or deepens the tree, so start narrow and confirm the call count with your own endpoint before scaling up.

SettingWhen it fitsEffect on runtime and call volume
Branching factorWider search when a single attack path is unlikely to reach the objective and the team can afford more candidate prompts per levelEach extra branch adds candidate prompts that the adversarial model writes and the target answers, so calls rise at every level of the tree
Search depth or widthDeeper search for objectives that need several refinement rounds; narrower search for quick checks of a deploymentDepth multiplies the number of levels, and calls compound with branching, so runtime is driven by the product of the two settings
Pruning behaviorKeep when off-topic or refused branches waste calls; review how aggressively branches are removed before relying on resultsPruning reduces later-level calls, but the savings depend on how often the scorer rejects candidates; confirm the saving in a trial run
Adversarial modelA capable model that writes effective attack variations, hosted where your data rules allow itAdds a second model in the loop; its latency and per-call cost set the runtime of every candidate it generates
ScorerAn LLM judge or classifier that matches your harm definition, used to decide which branches surviveA heavier scorer adds a call for each evaluated response; a lightweight rule-based check lowers per-branch cost but may miss subtle harms
Objective setA small, targeted set of objectives for a focused assessment; a broader set for coverage across harm categoriesRuntime scales with the number of objectives times the tree size, so each added objective multiplies total calls
Image inputMultimodal targets where the risk sits in images, and the team has confirmed the target accepts image inputsImage candidates add generation and target calls with larger payloads; the added cost depends on the model and image handling, so confirm it for your target
Stateful or stateless targetStateful targets that keep conversation history need the full branch context; stateless targets need each request to carry its own contextStateless targets often need the full history resent with each call, which increases payload size and token use on every branch

What the branching factor does to cost and duration

The branching factor is the main lever on what a TAP run costs and how long it takes, so set it deliberately before you schedule any run. Each branch that TAP expands produces a new adversarial prompt, which means one or more calls to the adversarial model, a call to the target for every candidate prompt, and a scorer call to judge each response. Because the search widens at every level and only survivors continue, the number of calls grows with the width and depth of the tree rather than with the number of objectives you test. The PyRIT benchmark scenario documentation states that TAP's branching search is slower and more expensive than lighter techniques, so treat it as a deliberate choice for hard objectives rather than a default for every test.

Cost has four components, and each is paid by a different party. Model tokens for the adversarial and scoring models are billed by whoever hosts those models, which may be your cloud account or a managed API. Target API calls are billed to the system under test, and they can also be rate limited, which stretches wall-clock time. Scorer calls add their own model or service charges, and compute time covers the machine running PyRIT and its SQLite or Azure SQL memory. Only the first two are usually large, but all four recur on every run, so a single pilot does not give you a fixed budget.

Measure before you commit. Run TAP on a small set of objectives with a narrow tree, record the calls made to each component and the elapsed time from PyRIT's memory, then scale the numbers to your full objective set and planned re-runs. Ask any partner for a quote that states the branching and depth settings assumed, the expected number of target and scorer calls per objective, the hosting of the adversarial and scoring models, who pays for each API, and whether the figures include repeat runs after fixes. Confirm rate limits with your target's provider before you size the pilot, since they often set the real duration.

Target requirements for stateful and stateless endpoints

A stateful target keeps conversation history on its side and identifies each conversation with a session or conversation ID. TAP branches share a common ancestry at the root, so if every branch reuses one session, a later branch can inherit turns from an unrelated branch. That contamination makes scores hard to attribute, because a response may reflect history the attack path never produced. PyRIT needs each branch to map to its own conversation identifier so the target's memory matches the path PyRIT recorded.

  • One session per branch: Confirm that the target issues or accepts a distinct session or conversation ID for each branch, and that PyRIT sends the right ID with every turn.
  • Pruned branches end cleanly: Check that discarding a branch does not leave its session open to be reused by a later candidate.
  • Shared ancestry handled deliberately: Decide whether branches copy the parent's history into a new session or replay it, and verify the target accepts that pattern.
  • Server-side memory limits: Ask the vendor or platform team how long sessions persist and whether there is a cap on turns or concurrent sessions, since TAP multiplies session count.
  • Recorded identifiers: Confirm that the session ID appears in PyRIT memory so a reviewer can trace each result back to its branch.

Before a full run, send two parallel test branches with different opening prompts and confirm the target's responses do not reference the other branch's content.

How image support changed TAP in v0.14.0

PyRIT v0.14.0 added image functionality to TAP, so the attack's adversarial prompts can carry images as well as text. It also added PAIRAttack as a TAP alias that comes with PAIR-definitional defaults. For a team, the practical effect is that a TAP run is no longer limited to text-only probing. Before you configure a run, confirm the version you have installed includes these changes, because a text-only configuration on an older release will not test the image path at all. The PyRIT v0.14.0 release notes are the place to confirm what the change covers.

For the target, image input means the endpoint must accept image content in the request, not just a text prompt. A chat endpoint that accepts text only will reject or silently drop image turns, so the run tests nothing on the image side. For the scorer, the judge that decides whether a response met the objective must be able to read the image output or the image-bearing response the target returns. A text-only judge can misclassify a harmful image response as benign. Ask the target owner which models or endpoints accept image prompts, and which input formats and size limits apply, before you assume a TAP run covers multimodal behavior.

Confirm three things in your environment before the first run: the target type you plan to use accepts image prompts in your PyRIT version, the scorer you chose can evaluate image responses, and the memory store records image turns so a reviewer can inspect them later. Also decide whether image branches count toward the same budget as text branches, since each image prompt adds cost on the target and the judge side. Record these decisions in the test plan so the image results can be reproduced and explained to a reviewer.

How to set up and run a TAP attack in PyRIT

This sequence takes a team from a clean Python environment to a verified, scaled Tree of Attacks with Pruning run against a target they are authorized to test. Each step ends with a check, so the team knows whether to continue, fix a setting, or stop before spending model calls on a broken configuration.

  1. Install PyRIT on a supported Python version

    The engineer who runs the tests creates an isolated 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 use that version where your platform allows it. Confirm the install by importing the package in a Python shell and checking the installed version matches the release your team has approved. If the import fails, resolve the interpreter version before touching any credentials.

  2. Configure credentials and settings files

    Store API keys and endpoint details for the target and adversarial model in the environment file at ~/.pyrit/.env, and place non-secret settings in ~/.pyrit/.pyrit_conf. Keep the files outside any shared repository and restrict their file permissions to the test operator. Check the configuration by running a single trivial request through each endpoint from a short script. A successful response with no credentials printed to the console or logs means this step is complete.

  3. Define the target and adversarial model

    Declare the system under test as a PyRIT target, and declare the adversarial model that generates attack prompts as a separate chat target. TAP depends on both, so confirm the target type matches how the application works: a stateful target keeps conversation context on its side, while a stateless target receives the full history with each request. Ask the application owner which type applies and whether the endpoint accepts image input if you plan to test multimodal behavior. Send one prompt to each target and confirm the replies arrive in the format your scorer expects.

  4. Choose the scorer and the objective

    Write one objective that describes the behavior the test is meant to elicit, phrased as a specific request the target should refuse. Select a scorer that evaluates whether the target's reply met that objective, such as an LLM-based judge, Azure AI Content Safety, or custom logic your team has reviewed. Run the scorer against two or three sample replies you already know are a refusal and a compliance, and confirm it separates them. A scorer that cannot tell these apart will report misleading results at scale.

  5. Run a pilot with limited branching

    Start TAP with a small branching setting and a shallow depth so the first run is cheap to repeat. The PyRIT benchmark scenario documentation notes that TAP's branching search is slower and more expensive than lighter techniques, so each added branch multiplies model calls against both the adversarial model and the target. Record the number of requests before the run starts and confirm the count matches your expectation once it finishes. Treat the pilot as a configuration check, not a result.

  6. Check the memory records

    Open the PyRIT memory store, which is SQLite by default or Azure SQL where configured, and review the conversations the pilot created. Confirm that each branch shows the adversarial prompt, the target reply, the score, and whether the pruning step kept or dropped the branch. Check that the stored records contain only what your data handling rules allow, and that the number of stored conversations matches the pilot's planned branches. Mismatches usually point to a target configuration issue or an unexpected retry.

  7. Scale the run and record the outcome

    Increase branching and depth in steps, repeating the request count check and memory review after each change. Keep the final configuration, the objective, the scorer version and the model identifiers together so another engineer can reproduce the run. Confirm with the application owner which results need to reach a findings report and how long memory records must be retained. Scale only after the pilot checks pass, because the cost of a misconfigured full run falls on your model account.

Security and operational risks when running TAP

A TAP run sends many adversarial and target requests, stores every branch in memory, and depends on scorers that decide what counts as a finding. The cards below cover the places where a run can leak credentials, expose harmful content, overspend, disrupt a live system, or produce misleading results.

Credential handling for keys

TAP uses two model connections at once: the target and the adversarial model that writes and refines branch prompts. Each needs its own key with the smallest scope that works, loaded from ~/.pyrit/.env or a secrets store rather than pasted into scripts or notebooks. Check that run logs and exported memory do not echo key values, and rotate keys after any shared or CI run.

Harmful content in memory

PyRIT's memory keeps every TAP branch, including the harmful prompts and target replies that scoring flagged, in SQLite or Azure SQL. Treat that database as sensitive data: restrict file permissions or database roles, decide who may query it, and set a retention and deletion routine before the first run. Confirm the storage location and who can read it on each test machine.

PyRIT documentation

Cost runaway from branching

TAP's branching search is slower and more expensive than lighter techniques, and every branch that is expanded or scored consumes tokens on both models. Set a branching factor, depth and total request budget in the attack configuration, and check provider spending limits before a run. Ask the team to estimate request counts for a single objective before running a batch across many objectives.

Impact on production targets

A TAP run sends hundreds of adversarial turns to whatever endpoint it is pointed at, which can trigger rate limits, fill logs, or open alerts in a live service. Point TAP at a staging or dedicated test deployment with its own keys and quotas, and agree a window with the owners of any shared system. Confirm the target's stateful or stateless behavior before the run so that conversation state does not carry over between branches.

Scorer reliability

TAP keeps or prunes branches based on scores, so a weak scorer steers the whole search toward the wrong prompts. A judge model that over-flags refusals or misses partial harms will produce findings that look convincing and are not. Before relying on results, run the chosen scorer against a small set of responses that a human has labeled, and record its disagreements.

Private vulnerability reporting

Problems found in PyRIT itself, such as a flaw in how it stores credentials or handles targets, should not go into a public issue. The project asks for reports through the Microsoft Security Response Center under its security policy. Put that channel in your internal runbook, and separate reports about PyRIT from findings about your own AI system, which follow your own disclosure process.

PyRIT on GitHub

Questions buyers ask about running TAP in PyRIT

What drives the cost of running a TAP attack in PyRIT?

Cost is driven mostly by the search itself. TAP branches each candidate prompt into several variants, sends them to the target, scores the responses and prunes weak branches over several rounds, so every branch and round adds target and model calls. The main cost lines are the target endpoint, the adversarial model that writes variants, the scorer that judges responses, and the time your engineers spend setting up objectives and reviewing results. The benchmark scenario documentation notes that TAP's branching search is slower and more expensive than lighter techniques. Ask any partner to show the expected number of target calls per objective, and whether those calls are billed to your account or theirs.

How long does a first TAP run take, and what sets the duration?

The duration depends on the branching factor, the number of pruning rounds, the response time of your target and the rate limits on each model endpoint. A stateful chat application with slow responses will take much longer than a stateless API with fast responses, even with identical settings. Setup of targets, credentials and objectives usually takes longer than the first run itself. No supplied benchmark gives a fixed duration, so confirm with your own environment by running a small pilot with a low branching factor and measuring calls and elapsed time before you plan a full sweep.

What does our team need to provide before a TAP run?

You need a target you can reach from the machine running PyRIT, credentials stored in the PyRIT configuration rather than in code, a clear objective the target should refuse, and a scorer that can tell a successful attack from a refusal. Stateful targets also need session handling so that each branch keeps its own conversation history. Your team should agree who reviews flagged responses, where results are stored, and which environments may receive test traffic. Confirm with your security team that the test traffic is permitted under your acceptable use and incident procedures.

Can our own engineers run TAP in PyRIT without a partner?

Yes, if your engineers are comfortable with Python, the PyRIT installation process and reading the target and scorer documentation. PyRIT installs with pip, supports Python 3.10 up to but not including 3.15, and its documentation recommends Python 3.13. The harder parts are usually not the installation but deciding the objectives, tuning the search so it is meaningful, handling stateful sessions and interpreting results for a risk owner. Many teams start in-house with one target and bring in outside help when they need coverage across several applications or formal evidence.

Is TAP or PAIR the cheaper attack to run?

PAIR is generally the lighter choice because it refines a single jailbreak prompt over iterations, while TAP explores a tree of candidate prompts and prunes it, which multiplies calls per round. PyRIT v0.14.0 added PAIRAttack as a TAP alias with PAIR-definitional defaults, so the two are closely related in code. Choose TAP when you need broader search coverage and can absorb the extra target and model calls. Choose PAIR when you want a cheaper, quicker check. Compare both on the same objective with a fixed call budget before deciding.

What would a partner scope for a TAP engagement?

A partner would normally scope the target inventory, the objectives and harm categories to test, the branching and round limits, the adversarial and scoring models, the environments allowed, and the form of the results. Deliverables typically include run configuration, raw conversation records, findings with severity, and a retest after fixes. Fixed-scope engagements are agreed in writing before work starts, so ask for a quote tied to these items, and ask what is excluded, such as ongoing monitoring, model hosting or fixes to your application. DeployOpen does not publish prices, and a quote follows from the written scope.

Does TAP support images, and what does that change for the target?

PyRIT v0.14.0 added image functionality to TAP, so the attack can work with image inputs as well as text. This matters if your target accepts images, because the candidate branches and the scoring must handle image content and the adversarial model must be able to produce or describe it. Confirm that your chosen target and adversarial model both support the modality you need, since image handling adds calls and may require different model choices. Check the release notes for the exact behavior of the version you install.

How DeployOpen scopes and delivers TAP testing

A TAP engagement is scoped in writing before any attack runs. DeployOpen agrees the objectives, the target systems, the harm categories to probe and the acceptance criteria for a finding, then records them in a fixed-scope document. For TAP, the scope should name the adversarial model, the judge or scorer, the branching and pruning settings, and the maximum number of model calls the test may make. The model-call budget is the most important item to agree up front, because TAP's branching search is slower and more expensive than lighter techniques, as PyRIT's benchmark scenario documentation notes. A written budget turns an open-ended cost into a bounded test, and it lets the client's team approve the spend before the first request is sent.

Target access is confirmed before the work starts. DeployOpen needs to know whether the endpoint is stateless, where each request carries the full conversation, or stateful, where the service keeps its own session, and whether a test account with the same permissions as real users is available. The client confirms the endpoint's rate limits, logging and content filters, and who on their side can stop a run. Where the system is an AI agent rollout, the scope can be extended to an AI agent rollout security review, which covers tool and file permissions, credential handling, SSO and admin settings alongside prompt injection. Customer AI security review support follows the same pattern when a software vendor's AI feature is being assessed by its customer.

Delivery ends with a findings report, not a raw log. Each finding records the objective, the winning conversation path, the scorer result, the model-call cost and a recommended fix such as a system prompt change, a filter rule or a tool restriction. DeployOpen then retests the fixed behavior against the same objective and budget and reports whether the finding is closed. Continuous testing, where TAP and related attacks run on a schedule after each model or prompt change, is available as an optional retainer. The client should ask for the retainer's scope, retest rules and what happens when a new model version changes the baseline. DeployOpen does not publish prices, so the quote follows from the written scope.

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.