Many-shot jailbreak testing with PyRIT

PyRIT's many-shot jailbreak tests whether a model that follows a long run of demonstrated compliance can be pushed past its refusals. This page covers how the attack is built, when to run it and what to confirm before you rely on the result.

On this page

How many-shot jailbreak testing with PyRIT checks long-context models

PyRIT's many-shot jailbreak prepends many faux question and answer pairs that demonstrate compliance, then asks the real request at the end. The attack relies on in-context learning: a model that reads a long run of examples where an assistant answers harmful questions may continue that pattern when the final question arrives. Teams deploying a long-context model that must hold its refusals need this test because the attack exploits the context window itself, so a model that refuses single prompts can still behave differently once the context is saturated with examples. The test is most relevant when the model accepts large prompts, when users or retrieved documents can inject long content into the conversation, or when a contract or internal policy requires evidence of refusal behavior under adversarial input.

The test does not cover everything a long-context deployment exposes. It does not check multi-turn escalation, where an adversarial model adapts across turns (see the Crescendo and TAP attacks), and it does not test indirect injection through documents the system reads, which is a separate XPIA workflow. It also does not tell you whether your output filters, system prompt or retrieval layer stop the request, because the result only shows what the target model returned. Ask your team to confirm which context lengths the production model accepts and whether the deployment adds a system prompt or moderation layer, since those change what the test measures. Plan to run the attack against the same configuration users reach, not only the bare model endpoint.

Setting up a many-shot run in PyRIT

This sequence takes a team from a clean Python environment to a completed many-shot jailbreak run, with the target, credentials and bundled example set configured so the stored conversations can be reviewed. Each step ends with a check that tells the operator whether to continue.

  1. Confirm a supported Python version

    Check that the workstation or runner has a Python version the PyPI package supports. The package supports Python 3.10 up to but not including 3.15, and the PyRIT documentation recommends Python 3.13, so install that version if it is available to you. Run the interpreter's version command and confirm the output falls in the supported range before creating a virtual environment for the test work. Done when the version prints as expected and the environment is isolated from other projects.

  2. Install PyRIT with pip

    Create a dedicated virtual environment and install the PyRIT package from PyPI with pip. Keep the install in the test environment rather than a shared system Python so that the version can be pinned and recorded with the test evidence. Confirm the install by importing the package in a Python shell and printing the installed version with pip show. Done when the import succeeds and the reported version matches the release you intend to cite in your report, such as the release notes you reviewed.

  3. Create the credentials and settings files

    Create the directory ~/.pyrit and add two files: .env for credentials and .pyrit_conf for settings. Put the API key or endpoint values for your target model in .env, and keep the file out of version control and out of shared logs. Use .pyrit_conf for non-secret settings that define the run. Restrict file permissions so only the test operator can read the credentials. Done when both files exist, the credentials file is readable only by its owner, and no secret appears in a file you plan to commit.

  4. Point PyRIT at the target under test

    Configure the target that the many-shot prompts will be sent to, using the target type that matches your deployment, such as a hosted model endpoint or a custom HTTP endpoint. Record the model name, version and any system prompt or safety filter in front of it, because the result only describes that exact configuration. Confirm the target is reachable with a single benign request before running any attack. Done when the test request returns a normal response and the target details are written into your run notes.

  5. Select the bundled many-shot example set

    Choose the bundled many-shot jailbreaking dataset that ships with PyRIT. Since v0.12.1 this dataset is bundled locally rather than fetched from GitHub at run time, so the run does not depend on a network call to retrieve it. Review the examples to understand the faux question and answer pairs that will precede the real request, and record which dataset version you used. Done when the dataset loads locally and you can list the number of examples it contains, which you should note in the test record.

  6. Run the many-shot attack against the target

    Start the many-shot attack in PyRIT so it prepends the example pairs to the objective and sends the combined prompt to the target. Confirm that the objective, the example set and the target are the ones you recorded, and that the run is scoped to a test environment you are authorized to assess. Watch the first few responses for errors such as context limits or authentication failures before letting the full run complete. Done when the run finishes or stops with a logged error that you can explain.

  7. Check the stored conversations in memory

    Open PyRIT memory, which stores conversations and results in SQLite by default in a local setup, and retrieve the conversations from the run. Confirm that each attempt shows the full prompt sent, the target response and any scoring result, and that the conversation identifiers match the run you started. Export or copy the records you need for review, keeping the prompt text and responses together. Done when every attempt from the run appears in memory with a complete request and response, and you can point an reviewer to those records.

Options that change what a many-shot test measures

This table compares the choices that shape a many-shot test: the example set, shot count, target type, scorer and memory backend. Read each row as a decision with a result consequence, and confirm the exact behavior in your PyRIT version before you fix the test design.

OptionWhen it fitsWhat it changes in the result
Bundled example setFirst baseline run against a model or endpoint you have not tested beforeGives a repeatable reference point, since the dataset is bundled locally in PyRIT v0.12.1 and later, but results only show how the bundled examples perform against your target
Custom examplesYour application serves a specific domain, language or persona that the bundled examples do not reflectTests whether your own harm categories and phrasing break the target, but results are harder to compare with published or other teams' runs
Low shot countQuick smoke test, or a target with tight context or cost limitsShows whether the model complies after few demonstrations; a refusal at low counts does not prove resistance at higher counts
High shot countLong-context models where the context window can hold many faux pairsTests the behavior the technique exploits; the prompt grows with each pair, so cost and latency rise and must be recorded per run
Stateless API targetModel endpoints where each request carries its full conversationEach request holds the full set of faux pairs, so results reflect the model alone and any gateway filters you include in the path
Stateful app targetChat applications that keep session history or add their own system prompt and filtersResults reflect the whole application; the stored history may carry earlier turns into the test, so reset sessions between runs
Scorer choiceAny run where you need a pass or fail judgment on each responseAn LLM judge, a content safety service or custom logic will label the same response differently, so record the scorer name and version with every result
SQLite memoryLocal development, a single tester and small test setsStores conversations and scores in a local file, which is simple to move but is not a shared store for a team
Azure SQL memoryTeam testing where runs must be shared, queried and kept under your Azure controlsCentralizes conversations and scores for review and retention, but adds database setup, access control and backup responsibilities

How the many-shot prompt flows from PyRIT to the target and scorer

The flow starts in the PyRIT attack on the test host, which builds the faux question and answer pairs and appends the real objective as one prompt. That prompt crosses the trust boundary to the target endpoint, and the response returns to a scorer. The conversation and score are then written to PyRIT memory, so check that the target logs and the memory store sit in the same controlled environment as the test host.

The many-shot prompt crosses from the test host into the target, then the response is scored and stored.

Security and operational risks of running many-shot tests

Many-shot runs put provider keys, harmful model output and paid token volume in one workflow. The cards below cover the controls to set before the first run, from credential storage and memory retention to authorization, cost and vulnerability reporting.

Store provider credentials carefully

PyRIT reads credentials from ~/.pyrit/.env and settings from ~/.pyrit/.pyrit_conf. A many-shot run needs a provider key with enough quota to send long prompts repeatedly, so a leaked file exposes paid access. Confirm the file permissions on the test host, keep the key scoped to a test project with a spending cap, and rotate it after the engagement. Never commit these files to a repository.

PyRIT docs

Control harmful outputs in memory

PyRIT stores conversations and scores in SQLite or Azure SQL. A many-shot run can produce harmful completions that persist in that memory and in any exported transcript. Decide before the run who may read the database, where it lives, and how long it is kept. Delete or encrypt the store when the test ends, and limit exports to the reviewers named in the test plan.

Test only authorized systems

A many-shot prompt is designed to push a model past its safety behavior, so running it against a system you do not own or have written permission to test is an attack, whatever the intent. Put the target, its owner, the test window and the permitted techniques in a signed scope document. Check that the endpoint in your PyRIT target configuration matches the approved one before the first request.

Plan rate limits and token cost

Each many-shot prompt repeats dozens or hundreds of example pairs before the real question, so every attempt consumes a large share of the context window. Concurrency multiplies that cost quickly. Ask the provider for the tokens per minute limit on the test deployment, set PyRIT concurrency and retries below it, and estimate the token bill for the planned number of prompts before starting.

Report PyRIT vulnerabilities privately

If a many-shot test exposes a flaw in PyRIT itself, such as a way the framework leaks credentials or memory contents, do not open a public issue. The project asks for private reports through the Microsoft Security Response Center under its security policy. Record the PyRIT version in use, since the 0.12.1 release is the security patch that changed how the bundled dataset is loaded.

v0.12.1 release notes

Confirm terms for the bundled dataset

Since v0.12.1 the many-shot dataset ships locally rather than being fetched from GitHub at run time. Local bundling makes the test reproducible, but it also means the dataset content is now in your environment. Read the project license and terms, confirm that your organization's use of the examples is allowed, and keep the dataset version recorded with the results.

PyRIT on GitHub

When a many-shot test is worth running against other attacks

A many-shot test earns its place when the target accepts long prompts and the team needs to know whether long context weakens its refusals. It is one signal among several, not a replacement for cheaper checks. A single-turn run of a known harmful objective tells you whether the basic guardrails hold. A multi-turn attack such as Crescendo tells you whether the conversation itself erodes them over time. Many-shot asks a different question: whether a model that has read dozens of compliant-looking exchanges in one prompt starts treating the real request as a continuation of that pattern. Run it alongside the single-turn baseline, not instead of it, so a failure can be attributed to the mechanism rather than to general weakness.

The deciding factors are the target's context length and how it is served. A model with a short window cannot receive a long many-shot prompt, so the attack tests little beyond truncation behavior, and the effort is better spent elsewhere. Ask the model owner or provider to confirm the maximum input length for the exact deployment, since hosted, self-hosted and quantized versions can differ, and confirm whether the serving stack truncates or rejects oversized input. Also check how the application wraps user input. A retrieval layer, a system prompt or a gateway that trims history can change what the model actually sees, so test the full path your users reach, not the bare model endpoint.

Cost is mostly the time to build and review the example set and the number of long requests sent, which scales with the number of shots and the attempts per objective. Token usage for the target is the recurring cost, and it is paid by whoever hosts the model. Ask the team running the test to state the shot count, the objectives, the scorer used to judge responses, and how results will be compared with the single-turn and multi-turn baselines. If the outcome will support compliance evidence or a go-live decision, agree the criteria for a pass before the first run.

Limits to confirm in your own environment

A many-shot run is only as meaningful as the conditions it ran under. The cards below cover the target's context window, how the endpoint handles oversized input, the fit of the bundled examples, the PyRIT version in use, and what a clean result does and does not prove.

Target context length

Many-shot depends on filling the target's context window with faux pairs before the real request. Confirm the maximum context length of the exact model and deployment under test, not the family name. Record the prompt size each run reached, so a result can be tied to a specific length. A run that never approached the limit tells you little about longer contexts.

Endpoint truncation behavior

Gateways, wrappers and hosted APIs may silently truncate, summarize or reject long prompts. If the start of the prompt is dropped, the examples that set up compliance never reach the model and the test measures nothing. Ask the provider or platform team how oversized input is handled, then check the received conversation in memory to confirm the examples arrived intact.

Fit of the bundled example set

PyRIT's many-shot dataset is a general set of faux question and answer pairs. Compare its topics with the harms in your scope, such as financial advice, medical content or customer data exposure. Where the examples do not resemble your harms, add domain-specific examples and label the run as a variant so results are not compared against the stock set.

PyRIT version in use

Since v0.12.1 the many-shot dataset ships locally instead of being fetched from GitHub at run time. Record the exact PyRIT version in every report, and confirm your environment runs v0.12.1 or later so the test does not depend on a remote download or on a version whose dataset differs. Pin the version so reruns use the same examples.

v0.12.1 release notes

A clean run is not a safety claim

A run that produces no successful jailbreak shows only that these examples, this prompt and this scorer did not succeed against this configuration on the day it ran. It does not establish that the model is safe, that other many-shot variants fail, or that the deployment is compliant. State the scope of the test in any report, and treat it as one input alongside other testing.

Questions teams ask before running many-shot jailbreak tests

What does a many-shot jailbreak test cost, and what drives the effort?

The main cost is the people time to scope the test, prepare the target, run it, and interpret the results. PyRIT itself is free and open source under the MIT license, so the cost is labor plus the model usage on the target and any scoring model. Effort rises with the number of target configurations, the number of objectives, how many example pairs you test at each length, and how much evidence you need to keep. Ask any partner for a quote built from a written scope that names the target count, objectives, scoring method and deliverables, and whether retesting is included.

How long does a first many-shot run take to set up?

Setup time depends mostly on your environment rather than on PyRIT. Teams with a working Python environment, a reachable model endpoint and approved credentials usually move fastest. Teams that still need to provision a host, agree on model access, set up secrets storage, or get sign-off for testing against a production system will spend more time on those steps first. PyRIT supports Python 3.10 up to but not including 3.15, and its documentation recommends Python 3.13, so confirm your interpreter version before planning the first run.

What must our team provide before a many-shot test starts?

Before testing starts, your team should provide:

  • Target access: the endpoint, model or application that will receive the prompts, in a test or staging environment where possible.
  • Credentials: API keys or service identities, stored outside source control and read by PyRIT from its configuration files.
  • Written authorization: sign-off from the system owner and, where your policy requires it, the security or legal function that the test may send adversarial prompts to that target.
  • Scoring criteria: a clear definition of what counts as a failure for your use case.
  • Logging and retention rules: where conversations are stored and who may review them.
Can an internal team run many-shot jailbreak tests without a partner?

Yes, an internal team with Python experience and access to the target can run the bundled many-shot example set without outside help. The work that usually needs more experience is designing objectives that match your deployment, choosing and checking the scorer, keeping memory records in a form reviewers can follow, and deciding what a result means for your system prompt and filters. If your team lacks time or red teaming experience, a partner can take that scope under a written agreement. Confirm your own capacity against the scope before deciding.

How should we read a many-shot result before reporting it?

Treat a single success as a signal to investigate, not as a final finding. Check the stored conversation to confirm the target actually produced the harmful content rather than a refusal or an unrelated answer, and confirm the scorer judged it correctly on a sample. Repeat the run, because model output varies between attempts. Record the number of example pairs, the model version and the system prompt used, so a later rerun can be compared fairly. Report the result with the conditions under which it occurred, and rerun after any change to the model, prompt or filters.

Does PyRIT's many-shot test tell us whether our model is safe?

No. A many-shot run tests one technique against the configuration you point it at, at the time you run it. It cannot show that other attacks will fail or that the system is safe in general. It is most useful as a repeatable check that long-context behavior has not regressed after a model, prompt or filter change, and as one input to a wider testing program. Ask any partner to state the limits of the test in writing before work starts.

Where do we confirm the current bundled dataset and PyRIT version?

The many-shot example set has been bundled locally since v0.12.1, so PyRIT no longer fetches it from GitHub at run time. Check the release notes for the version you plan to use, since later releases change APIs and documentation. Confirm your installed version with your own environment before you write the test plan, and review the PyRIT documentation for the version you deploy.

How DeployOpen scopes and delivers PyRIT many-shot testing

DeployOpen runs PyRIT many-shot testing as a fixed-scope engagement, with the target, the prompt set and the scoring agreed in writing before any run starts. We install and configure PyRIT in an environment you control, then document the results so your security and compliance teams can review them.

How we scope

  • Agree in writing which target models or applications the many-shot tests cover and who owns each endpoint
  • Confirm the context window and shot counts to test, based on what the target accepts
  • Define which content harms or policy areas the faux dialogue prompts will probe
  • Set the scorer, success criteria and how refusals and partial answers get recorded

How we build

  • Install PyRIT in your infrastructure and configure credentials through ~/.pyrit/.env and ~/.pyrit/.pyrit_conf
  • Load the bundled many-shot dataset locally and adapt the example set to your objectives
  • Run baseline single-turn requests alongside many-shot runs so results can be compared
  • Verify memory storage in SQLite or Azure SQL so every conversation can be reproduced

How we hand over

  • Deliver a findings report that lists each many-shot run, shot count, prompt set and observed result
  • Provide the scripts, configuration files and scorer settings needed to rerun the tests
  • Walk your team through the memory records so each finding can be traced to its evidence
  • Document remediation options, such as context limits, input screening or output filtering, for your own engineers

How we support

  • Retest after your fixes and record whether the many-shot results changed
  • Plan PyRIT upgrades and dataset updates alongside your own release schedule
  • Ongoing support, upgrades and continuous testing are available as a retainer
  • Confirm support terms and retest scope in the written quote before work begins

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.