Writing custom PyRIT scenarios for your application

Packaging your application's objectives, datasets, techniques and scorers into a PyRIT scenario so the assessment runs from pyrit_scan with one command and comparable results across runs.

On this page

Why teams write a custom PyRIT scenario for their application

A packaged scenario tests generic harm categories, but your application has its own harms, policies and users. A support assistant for a bank, a clinical summary tool and a internal coding helper can each fail in ways that a standard category list will not surface. A custom PyRIT scenario lets your team define the objectives your application must refuse, the datasets that reflect your policies, the techniques that match how your users or attackers actually interact with it, and the scorers that decide what counts as a failure. PyRIT's documentation on scenarios gives illustrative patterns for this, including a quick sample drawn from HarmBench, a check focused on one harm such as violence, and a scenario built around the curated datasets a specific compliance requirement calls for. Each pattern bundles the same kinds of pieces into one named unit.

PyRIT is built from targets, converters, scorers, attacks, memory and datasets, and a custom scenario is the place where your choices for each of these are written down together. The target is the endpoint or web app under test, converters transform prompts before they reach it, scorers judge the responses, attacks drive the conversation, memory records what happened, and datasets supply the objectives. Naming the scenario turns those choices into something a colleague can review, change in one place and run again. Before you start, confirm which components your application needs and which packaged scenarios already cover parts of your risk, so you extend rather than duplicate them.

Repeatability is the reason to package the work. Once the scenario is defined, pyrit_scan can run it against the same registered target on each release or after a model or prompt change, which makes results comparable over time. That only holds if the objectives, dataset versions, technique list and scorer settings stay fixed between runs, so decide who owns the scenario definition and how changes are reviewed. Ask your team to record which policies each objective traces back to, because compliance reviewers will ask why each test exists. Treat the first version as a baseline, not a finished assessment.

What goes into a PyRIT scenario definition

A custom PyRIT scenario is a set of decisions that stay fixed between runs: what the application should not do, the prompts used to test it, the techniques that deliver them, and how responses are judged. The cards below cover each decision, where it lives, and what should change between runs so results stay comparable.

Objectives

Objectives are the behaviors you want the application to refuse or handle safely, written as specific goals such as disclosing internal pricing rules or giving account data to an unverified caller. Decide who owns the list, since risk, compliance and product teams usually disagree on scope. Between runs, objectives should stay stable so a change in results reflects the system, not the test. Check that each objective maps to a risk your team has accepted or must mitigate.

Datasets

Datasets hold the seed prompts that start each attack, and they are where most application-specific content belongs. Combine general seed sets with prompts written from your own user flows, tools and data. Version the dataset files alongside the scenario so you can explain later which prompts were run. Between runs, the dataset can grow, so record its size and version with each result.

PyRIT scenario docs

Techniques

Techniques are the attack methods applied to each seed prompt, from single-turn delivery to multi-turn strategies such as Crescendo, TAP and Skeleton Key. Pick techniques that match how your users or attackers would reach the application, such as a multi-turn chat flow or a single API call. Each added technique increases request count and run time, so choose deliberately. Keep the technique list fixed across comparable runs.

Scorers

Scorers decide whether a response counts as a successful attack. Options include LLM-based judges, Azure AI Content Safety, and custom logic that checks for your own sensitive values, such as account identifiers or internal document strings. Custom checks are often the most useful signal for application-specific risk, but they need tests of their own. Confirm the scorer's false positive and false negative rate on sample responses before trusting its verdicts.

Target registration

The target is the application under test, registered with its endpoint, authentication and request format so that the scenario can address it by name. Registration is the place to keep secrets out of scenario files, using the PyRIT configuration and environment files. Between environments, such as staging and production, only the registered target should change. Confirm which target settings are safe to log and which must stay out of job output.

Labels and memory

Labels tag each run with the build, application version, environment and owner, and PyRIT memory stores conversations and results against those labels. Consistent labels let you compare the same scenario across releases and retrieve the exact transcripts behind a finding. Decide the retention and access rules for memory before the first run, because it can contain sensitive prompts and responses. Confirm where the memory store lives and who can query it.

Which scenario building blocks to customize and when

This table compares the building blocks you can change when packaging a custom PyRIT scenario, from reusing a packaged scenario with a curated dataset to writing your own scorer. Read each row against your application's risk profile, and start with the smallest change that tests the harm you care about.

OptionWhen it fitsTrade-offWhat to confirm
Reuse a packaged scenario with a curated datasetYour application's harms match a category a packaged scenario already covers, and you need a quick baselineResults reflect the packaged objectives, so application-specific failure modes may go untestedWhich built-in datasets the scenario loads and whether they match your use case
Add a custom objective setYour application has domain harms, such as a banking assistant leaking account rules, that generic datasets missObjectives must be written and reviewed by people who know the application and its policiesWho signs off the objectives and how they are versioned alongside the scenario
Single-turn techniquesYou need fast, repeatable checks on each prompt, for example in a pipeline on every changeMisses failures that only appear after several turns of conversationWhich techniques are in the scenario and how many prompts each run sends
Multi-turn techniquesYour application keeps conversation state and users can steer it over many turnsCosts more requests per objective and produces longer runs that are harder to rerun quicklyAdversarial model access, request budget and whether the target keeps session state
Built-in scorersYour harm categories fit standard harm or refusal judgments and you want results comparable to other runsGeneric judges may disagree with your policy, so borderline results need manual reviewWhich scorer applies to each objective and how its output is recorded in memory
Custom scorerSuccess depends on application-specific rules, such as a disallowed account number format or an internal policy phraseYou must validate the scorer's accuracy yourself before trusting its resultsWho owns the scorer logic, the test cases that validate it, and how false positives are reviewed

Building and running your first custom scenario

This sequence takes a team from a fresh PyRIT install to a limited, repeatable run of an application-specific scenario from pyrit_scan. The output is a scenario definition your team can rerun and a first results set to review.

  1. Install PyRIT on a supported Python version

    Create a virtual environment on Python 3.10 or later but below 3.15, then install PyRIT with pip. The PyRIT documentation recommends Python 3.13, so use that if your platform team already supports it. Confirm the install by running pyrit_scan with the help flag and checking that the command starts without import errors. Pin the installed version in your project so later scenario runs use the same release.

  2. Configure the environment and settings files

    Create the credentials file at ~/.pyrit/.env for keys and endpoints the target needs, and the settings file at ~/.pyrit/.pyrit_conf for defaults such as memory and scenario paths. Keep secrets out of shared configuration and out of source control. Check the setup by running a basic command that reads configuration without printing secret values. If the target is an Azure service, confirm with your platform team how identity will be provided before adding keys to the file.

  3. Register the application target

    Describe your application as a PyRIT target, either a custom HTTP or WebSocket endpoint or a web app driven through Playwright, and register it so pyrit_scan can address it by name. Agree with the application owner which request and response format the endpoint uses, how authentication is passed, and whether the target keeps conversation state. Confirm registration by listing targets and seeing your entry with the expected name. Send one harmless test message to verify the response is captured.

  4. Write objectives and a small dataset

    Write the objectives your application must not fulfill, phrased as the request an attacker or careless user would make. Keep the first dataset small, a handful of objectives drawn from your application's risk register, such as data disclosure, off-topic misuse or policy violations specific to your product. Store them in a file your team can review and version. Confirm the file loads by running a dry read that reports the number of objectives it found.

  5. Define the scenario with techniques and scorers

    Create the scenario definition that ties your objectives to the attack techniques you want to run and the scorer that decides whether each attempt succeeded. Start with a single-turn technique and one scorer whose criteria you can explain to the application owner. Document each choice in the scenario file so reviewers can see what is tested and why. Check the definition by loading it without errors and confirming the techniques and scorer appear as expected in the scenario summary.

  6. List scenarios to confirm registration

    Run the command that lists available scenarios and confirm your custom scenario appears under its name alongside the packaged scenarios. If it is missing, check that the scenario file is in the directory PyRIT searches and that the definition loaded without errors. Record the scenario name in your team's runbook so everyone calls it the same way. Registration is complete when the scenario name appears in the list exactly as defined.

  7. Run pyrit_scan on a limited dataset

    Run pyrit_scan against your registered target and scenario, limiting the number of objectives to a small subset for the first run. The limit keeps requests and cost low while you confirm the target responds, the scorer produces results and memory records each attempt. Watch for authentication errors, timeouts and empty responses, and fix them before expanding the dataset. The run is complete when the command exits without a failed-target error and the attempts are recorded.

  8. Read the output and record the baseline

    Review the scan output for each objective: the attack attempted, the target response and the scorer's verdict. Check that the verdicts match what a human reviewer would decide on a sample of responses, and adjust the scorer or objectives if they do not. Save the results and the scenario version as the baseline for future runs, so later changes to the application or scenario can be compared. The step closes when the team agrees the scorer is trustworthy enough to expand the dataset.

How a custom scenario moves from definition to scored results

The run starts with your scenario definition, which names the objectives, datasets, techniques and scorers for one application. pyrit_scan loads it and sends each objective through converters and attacks to the registered target, which is the boundary where your application and its credentials sit. Responses return to the scorers, and every conversation and score is written to PyRIT memory, SQLite or Azure SQL, with labels. Check that the target registration and ~/.pyrit/.env credentials stay inside the trust boundary, and that labels identify the run.

Custom scenario flow from definition through the target to stored, scored results.

Keeping results repeatable across runs and builds

Two runs of a custom scenario are only comparable if the inputs that shape the result stay fixed. Before you treat a change in results as a change in the application, pin the dataset version the objectives and seed prompts were drawn from, the PyRIT version installed in the runner, the target registration that points the scenario at the application under test, and the scorer configuration that decides whether each response counts as a success. If any of these moves between runs, a difference in the findings may reflect the test setup rather than the system. Keep the dataset files in version control next to the scenario definition, record the installed version in your build output, and treat edits to the target or scorer settings as changes that need their own review.

Labels are the other half of comparability. Give each run a label that identifies the application build, the scenario and the environment, so that memory entries can be filtered back to a specific release. Confirm with the PyRIT documentation for your installed version which run metadata PyRIT writes to its memory store, such as scenario name, operator and labels, and whether it records the scorer and adversarial model settings. If a field you need for an audit trail is not recorded, store it alongside the run in your own pipeline artifacts.

Some variation cannot be removed. LLM-based scorers and adversarial models that generate multi-turn attack messages can return different outputs for the same input, so a single run can move up or down without any change in the application. Decide in advance what counts as a regression, for example a change in the number of successful objectives beyond a threshold you set from repeated baseline runs on an unchanged build, or any new success on an objective that previously failed. Run the baseline several times before you set that threshold, and document which scorer and adversarial model versions the threshold assumes so that a future model change is not mistaken for an application regression.

How security, product and platform teams use the scenario

Security engineers own the definition of the assessment. They decide which harms matter for the application, write the objectives and seed prompts, choose the techniques and select or build the scorers that decide whether an attack succeeded. Their work sets the scope of every later run, so changes to objectives or scorers should be reviewed and versioned like code.

  • Objectives: Write objectives that describe the behavior the application must refuse, such as disclosing internal configuration or acting outside its permitted tools.
  • Datasets: Keep seed prompts in version-controlled files so a reviewer can see exactly what changed between runs.
  • Techniques: Start with a small set of single-turn techniques before adding multi-turn strategies that cost more requests.
  • Scorers: Document what each scorer counts as a failure and test it against a few responses you have labeled by hand.
  • Handoff: Pass the scenario definition and scorer notes to product and ML reviewers, who need them to interpret results.

Check that every objective maps to a policy statement the application team has agreed to.

Security and operational considerations for custom scenarios

A custom scenario bundles objectives, prompts, techniques and scorers that together can reveal how your application fails. The cards below cover where that material lives, who can read it, and which endpoints and versions your team must control before a scenario runs in a shared pipeline.

Credentials in the env file

PyRIT reads credentials from ~/.pyrit/.env and settings from ~/.pyrit/.pyrit_conf. A custom scenario often needs keys for the target, the adversarial model and the scorer, so one file can grant access to several paid endpoints. Keep the file out of repositories, restrict its permissions to the account that runs the scan, and confirm which keys each scenario actually reads before you copy the file to a shared runner.

PyRIT documentation

Keep objectives out of job logs

Custom objectives and jailbreak-style prompts are sensitive because they describe the exact weaknesses you are probing. Pipeline logs are often readable by many developers and retained longer than the scan. Configure your CI system to mask output from the scan step, write results to a restricted artifact store, and print only scenario names and pass or fail counts to the console.

Treat attack content as sensitive data

Your objective datasets can encode proprietary policies, customer scenarios or regulated topics, and the attack transcripts can contain model output that quotes internal data. Classify the dataset files and exported conversations with the same label as the system under test, store them in the same region and encryption boundary, and decide who may add or change objectives before a scenario is approved.

Memory needs access and retention rules

PyRIT memory stores conversations and results in SQLite or Azure SQL, so every scan leaves a full record of prompts and responses. A local SQLite file on a laptop and a shared Azure SQL database need different controls. Define who can query memory, how long records are kept, how they are deleted, and whether backups inherit the same rules. Ask your security team to review these settings before the first shared run.

Count model endpoints as data flows

Each scenario sends target prompts to the system under test, and the adversarial model and scorer receive the prompts and responses to generate or judge attacks. Each of those endpoints is a data processor in your data flow diagram, even when it is only used for testing. List every endpoint a scenario calls, confirm where each one processes data, and check that the provider terms match your approval for that data.

Pin versions and report vulnerabilities

The original Azure/PyRIT repository was archived on 27 March 2026 and development continues at microsoft/PyRIT, so confirm which repository your pipeline installs from. Pin the PyRIT version your scenarios were tested against and re-run a baseline scenario before each upgrade. Vulnerabilities in PyRIT itself go to the Microsoft Security Response Center under the project's security policy, not into public issues.

PyRIT releases

Questions teams ask before writing a custom PyRIT scenario

How much effort does a custom PyRIT scenario take?

Effort depends mostly on three things: how much dataset curation the objectives need, how much scorer tuning the application's harms require, and how easily the team can reach the target. A scenario that reuses an existing target and a small set of well-understood objectives is a small job. A scenario that needs new objectives written by domain experts, a custom scorer checked against human judgment, and a target behind login or network controls is a much larger one. Ask any partner to break the quote into these three components so you can see which one drives the number.

Can an in-house team build a custom PyRIT scenario without outside help?

Yes, if the team has Python skills, has operated PyRIT before, and can give the work sustained time. The framework is open source under the MIT license, and the scenario docs describe the pieces a team assembles. The risks lie in less visible work: deciding which harms matter for your product, validating that the scorer agrees with a human reviewer, and keeping the scenario running after PyRIT releases change its interfaces. Many teams build the first version themselves and bring in outside help for the scoring design or for a review before they rely on the results.

What does the work need from our team?

Plan for four inputs before the build starts:

  • Target access: a registered endpoint or web app that PyRIT can reach from the runner, with a named owner who can change it during testing.
  • An objectives owner: someone who can say which harmful or unwanted behaviors the application must not show, in the terms your business uses.
  • Test credentials: accounts with the roles real users hold, kept out of job logs and stored in your secrets system.
  • A model budget: the attack and scoring calls use model access, and multi-turn techniques send many more requests than single-turn ones. Confirm the budget and rate limits with the model provider and your finance owner.
How long does a first version take, and what changes that?

The timeline is set by the readiness of your inputs, not by the PyRIT configuration itself. A first version moves quickly when the target is reachable, the objectives are agreed, and the scorer has a clear pass or fail definition. It slows when access requests go through several teams, when objectives need legal or safety review, or when the team has to decide what counts as a finding. Ask for a timeline that lists these dependencies as milestones, so the schedule shows which party is waiting.

What does ongoing maintenance look like after PyRIT upgrades?

Maintenance is recurring work. PyRIT is an active project with releases that have changed its architecture and APIs over time, so a scenario written against one version may need edits after an upgrade. Each upgrade needs a test run against a known target, a comparison of results with the previous baseline, and a check that the scorer still behaves as expected. The application also changes, so objectives and datasets need periodic review. Agree on who owns upgrades, how often the scenario is re-run, and where the results are stored, since those decisions decide whether the work stays current.

What drives the quality of the scorer, and how do we check it?

The scorer decides whether an attack worked, so its quality sets the value of every result. Its accuracy depends on how precisely the pass or fail rule is written, which examples the team uses to calibrate it, and whether a human reviewer has checked a sample of its verdicts. Plan a review step in which people who know the application label a set of responses and compare their labels with the scorer's output. Disagreements show whether the rule needs rewording or the scorer needs a different approach. Ask for this step explicitly in any scope.

Do we need a managed service instead of building the scenario ourselves?

A managed service makes sense when the team needs repeatable results but does not want to own the scenario, scorer and upgrade cycle. DeployOpen plans, implements and tests PyRIT-based assessments in infrastructure you control, under a written scope with agreed deliverables, and can offer ongoing support as a retainer. Whichever route you choose, insist on owning the scenario code, the objective datasets and the stored results, so the assessment remains usable if the relationship ends.

Where to read the scenario documentation

Start with the scenarios page of the PyRIT 1.1.0 documentation, because it describes the scenario model that a custom scenario plugs into and gives examples of what teams write, such as a quick HarmBench sample, a violence-focused check or a scenario built on curated datasets for specific compliance requirements. Read it before you copy any structure from another project, so your objectives, datasets, techniques and scorers map onto the names the release actually uses. The page is at PyRIT documentation 1.1.0: Scenarios.

Use the main PyRIT documentation 1.1.0 for the surrounding pieces: targets, converters, scorers, memory and the configuration files that a scenario relies on, including ~/.pyrit/.env for credentials and ~/.pyrit/.pyrit_conf for settings. Those are the pages to check when your scenario fails to find a registered target or writes results you did not expect. Scenario class names, registration behavior and options can change between releases, so confirm them against the version you install rather than against an older example.

Pin the PyRIT version in your project, then verify the documentation matches that exact release before you write code. The current documented release is 1.1.0, released on 4 September 2026, but a team that pins a different version should read the docs for that version and compare its release notes on the project's GitHub releases page. Record the pinned version next to your scenario so a later upgrade can be tested against the same assessment, and confirm with your platform team which PyRIT version your CI runners and shared environments install.

How DeployOpen scopes and delivers custom PyRIT scenarios

This sequence turns an application's risks into a written scope, a tested PyRIT scenario and documented results that your team can rerun with pyrit_scan. It also sets out who owns each decision and what the handover contains.

  1. Agree the written scope

    DeployOpen and your team agree in writing which application behaviors are in scope, which harm categories and objectives apply, which datasets and scorers will be used, and what target access is needed. Your security or AI risk owner signs off on the list of objectives before any scenario code is written. The step is done when the scope document names each objective, dataset, scorer and target, and lists what is out of scope.

  2. Confirm target access and test accounts

    Your team provides the endpoint or application target, test credentials, and the configuration PyRIT needs to reach it, such as a custom HTTP or WebSocket endpoint or a web app driven through Playwright. DeployOpen confirms that the target responds to test prompts from the environment where scans will run, and that test data contains no production records. The step closes when a smoke request returns a response that PyRIT can record.

  3. Build the objectives and dataset

    DeployOpen writes or adapts the objective list and seed dataset so it reflects how your application is used, such as the tasks, user roles and sensitive data it handles. Your team reviews the prompts for legal, brand and content sensitivity before they are approved. The output is a versioned dataset file that the scenario loads, with a short note on the risk each group of objectives tests.

  4. Select techniques and scorers

    DeployOpen chooses which PyRIT attack techniques and converters apply to your objectives, and which scorers decide whether an attack succeeded, such as an LLM judge, a content safety scorer or custom logic written for your application's policies. Your team reviews a sample of scorer decisions against expected outcomes to confirm the scoring matches your policy. The step is complete when the scorer review record shows agreement on the sample cases.

  5. Package the scenario and register it

    DeployOpen packages the objectives, dataset, techniques and scorers into a custom PyRIT scenario and registers it so that pyrit_scan can list and run it by name against the registered target. Configuration values such as credentials stay in the environment files that PyRIT reads, not in the scenario code. The step is done when the scenario appears in the scenario list and a dry run completes without errors.

  6. Run and verify repeatable scans

    DeployOpen runs the scenario with pyrit_scan on a limited dataset first, then on the full set, and repeats runs to check that results are stable across attempts and that retries and partial results behave as expected. Each run is labeled in PyRIT memory so results can be traced back to a scenario version and target. The step closes when two consecutive runs on the agreed configuration produce comparable results and the run logs are clean.

  7. Document results and hand over

    DeployOpen delivers a findings report that explains what the scenario tested, the scorer settings, the run history, the successful attacks with suggested fixes, and the exact pyrit_scan command your team uses to rerun it. Your team receives the scenario code, dataset and configuration notes in a repository you control. The handover is complete when your team runs the scenario once without DeployOpen present and the output matches the report format.

  8. Decide on retainer support

    After handover, you can choose a retainer for upgrades when PyRIT or the target changes, updates to objectives as the application grows, and continuous testing on a schedule you agree. Pricing and scope for a retainer come from a written quote, so ask for the upgrade coverage, the number of scenario changes included, and how new findings are reported. DeployOpen runs the security testing and documents the results, but it does not issue audit reports or certifications, so ask your auditor which evidence they will accept.

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.