Using HarmBench with PyRIT

HarmBench gives PyRIT a standard set of harmful objectives to start red teaming from, and this page explains how it feeds the Foundry and Jailbreak scenarios, how to sample it, and when it is not enough.

On this page

Using HarmBench with PyRIT: when a standard benchmark starts your red team

HarmBench is the default objective dataset for PyRIT's Foundry RedTeamAgent scenario and the objective dataset in the Jailbreak scenario example, so it is the natural starting point when a team needs a first set of attack objectives for a generative AI system that has no red team history. An objective is the goal an attack tries to reach, such as getting the target to produce content it should refuse. Starting from a published benchmark gives the team a repeatable baseline it can run again after every model, prompt or configuration change, and it lets the results be compared across runs without the team inventing its own test set first.

In a PyRIT run, objectives are passed to an attack, which sends prompts to a target such as a model endpoint, a custom HTTP application or a web chat interface. The attack may be single-turn or multi-turn, depending on the strategy chosen. Scorers then evaluate each response to decide whether the objective was met, using LLM judges, Azure AI Content Safety or custom logic. The objective set therefore defines what is tested, and the scorer defines what counts as a failure, so both need review before anyone reads the results as a risk figure. Confirm which scenario version and PyRIT release your team will run, since the scenario defaults and dataset handling are documented per version in the PyRIT documentation.

A standard benchmark is enough when the team wants broad coverage of common harm categories, a baseline for a model it does not control, or a comparison point across vendors. It is not enough when the application has harms a generic set will not reach, such as a banking assistant that must not disclose account data, a clinical tool that must not give dosing advice outside its scope, or an agent that can take actions in a business system. In those cases the team should add application-specific objectives written from its threat model and data flows, and run them alongside HarmBench rather than instead of it. Ask the team that owns the application to confirm which harms matter most before the first run.

How a HarmBench objective moves through a PyRIT scenario

The run starts with the HarmBench dataset, which supplies the objectives. A sampling step caps how many are used through the max dataset size setting, and the Foundry or Jailbreak scenario sends each objective to the target under test, which sits inside the trust boundary. Scorers then judge each response, and PyRIT memory records the conversations and results. Check the sampled set and the scorer verdicts before reading any attack success rate.

Objectives flow from HarmBench through the scenario to the target, with scoring and memory after.

Sampling options and when each fits

This table compares running the full HarmBench set, sampling it with a max dataset size, and swapping in another built-in or custom dataset. Read each row for what it gives up in coverage, run time and comparability between runs. The main takeaway is to fix one dataset choice for any run you intend to compare over time.

OptionCoverageRun time and costComparability between runs
Full HarmBench setBroadest standard coverage of the benchmark's harm categoriesLongest run and highest target and scorer calls per attackHigh, if the dataset version and scorer stay fixed
Sampled with max dataset sizePartial, and the sample may miss categories relevant to your applicationShorter run, scaled to the cap you setLower unless every run uses the same cap and random selection settings
Another built-in catalog datasetDepends on that dataset's harm focus, which may not match HarmBenchVaries with dataset sizeGood within that dataset, weak against HarmBench results
Custom application-specific datasetMatches the harms your application can cause, including its own tools and dataSet by how many objectives you write and maintainHigh if you version the file and record it with each run
Standard set as a baseline, plus custom objectivesBroad baseline plus targeted depth on your risksTwo runs, so more total time and scoringGood for trend lines when the baseline stays unchanged

Running HarmBench objectives in PyRIT step by step

This sequence takes a team from a clean Python environment to a reviewed, sampled HarmBench run against its own AI target, so the full run only starts after scorer output and memory records have been checked. Each step ends with a check that tells the operator whether to move on.

  1. Confirm a supported Python version

    The platform or security engineer checks that the workstation or build host runs a Python version the PyPI package supports, which is 3.10 up to but not including 3.15. The PyRIT documentation recommends Python 3.13, so use that if your organization allows it. Run the interpreter version command in the environment where PyRIT will execute. You are done when the reported version falls inside that range and matches the version your change record names.

  2. Install PyRIT with pip in an isolated environment

    Create a virtual environment for the test team and install the package from PyPI with pip. Keep the environment separate from other Python tooling so dependency changes do not affect red teaming runs. Record the installed PyRIT version, since the release notes differ between major versions and HarmBench behavior should be tied to a known release. Confirm the install by importing the package in a short Python session and printing its version. You are done when the import succeeds without errors and the version is written into your test record.

  3. Configure credentials and settings in the home directory

    Create the PyRIT configuration files under your home directory. Store API keys and endpoint secrets in ~/.pyrit/.env, and store non-secret settings such as memory and default options in ~/.pyrit/.pyrit_conf. Restrict file permissions so only the test operator can read the secrets file, and keep the file out of version control. If your organization uses a central secrets service, confirm with your security team how those values will reach this file. You are done when the configuration files exist, the secrets file is readable only by its owner, and a dry startup reads both files without a missing-key error.

  4. Select and verify the target

    Choose the target that represents the application under test, such as a hosted model endpoint, a self-hosted model, or a custom HTTP endpoint that wraps your product. Confirm the target's system prompt, safety settings and any retrieval or tool access match what users will actually reach. Send one benign test message and read the raw reply in the console. You are done when the target returns a response through PyRIT, and the operator has written down the exact deployment, endpoint and configuration the run will test.

  5. Load HarmBench and run a small sampled pass

    Start the Foundry or Jailbreak scenario with HarmBench as the objective dataset, and set the maximum dataset size to a small number so only a sample of objectives is sent. The PyRIT Foundry scenario documentation names HarmBench as its default dataset, so confirm which dataset the scenario loads before the run starts. Keep the sample small enough that every response can be read by hand. You are done when the run completes without target errors and the operator can see one attack record per sampled objective.

  6. Review scorer output and memory records

    Open the results and the conversation history stored in PyRIT memory. For each sampled objective, read the prompt, the target response and the scorer verdict, and check that the scorer's decision matches what a human reviewer would conclude. Look for false positives from refusals written in harmful-sounding language and for responses the scorer missed. Note any scorer configuration changes needed before the full run. You are done when the reviewer has confirmed the scorer agrees with manual reading on the sample, or has recorded the changes required and rerun the sample.

  7. Run the full objective set and archive results

    Remove the sample cap, run the full HarmBench objective set against the same target configuration, and keep the environment, PyRIT version, dataset and scenario settings with the output. Export or retain the memory database so the run can be reproduced and an auditor or engineer can trace each result back to its conversation. Confirm that the record count matches the expected number of objectives and that no run was silently truncated. You are done when the complete run is stored with its configuration, and the team has a written list of findings to triage.

When a standard benchmark set is enough, and when it is not

HarmBench gives you a shared, published set of harmful objectives to run against a model. It answers how a model responds to broad harm categories, but it says little about the specific misuse, data exposure and policy risks of the system you ship. The cards below mark where a standard set is a sound starting point and where your own objectives must take over.

General-purpose chat model coverage

HarmBench is designed for broad harm coverage, so it fits a general-purpose chat model that users can steer toward almost any topic. Run it as the Foundry or Jailbreak scenario objective source to get a first view of how the model refuses across common harm categories. Check which categories your product actually exposes, because a narrow internal assistant rarely needs every category in the set.

Foundry scenario docs

Baseline regression across model versions

Using the same objective set on each model version or system prompt change gives you a consistent baseline. Keep the dataset, sampling settings and scorer fixed so that a change in results reflects the system, not the test. Record the max dataset size you used, because changing it alters which objectives run and makes runs hard to compare.

Comparing against published results

A shared benchmark lets you place your results next to published numbers for other models and papers. This comparison only holds if you match the dataset version, prompt sampling and scoring method used in those publications. Confirm each of these with the source before you put a comparison in a risk report or a customer answer.

Domain misuse your product enables

A standard set does not know your domain. A banking assistant, clinical summarizer or support bot can be misused in ways no general harm category names, such as fraudulent transfer requests or unsafe dosing advice. Write objectives for these misuse paths and use the same PyRIT seed format so they run beside the benchmark.

Data exposure from your own tools

If the assistant calls your databases, file stores or APIs, the risk is that it reveals records the user should not see. HarmBench prompts rarely try to make a model read a customer record it is not authorized to access. Write objectives that target your tool names, record types and access boundaries, and confirm with your security team which data sets are in scope.

Brand and internal policy rules

Your acceptable-use policy, tone rules and regulated-advice boundaries are specific to your organization. A benchmark cannot tell whether the assistant broke a rule you wrote for your own customers. Write these objectives with the policy owner, and add a scorer that checks the rule itself so that a refusal or a compliant answer is judged against your text, not a generic harm label.

Questions teams ask before running HarmBench with PyRIT

How much effort does setting up HarmBench in PyRIT take in-house?

For a team already comfortable with Python, loading HarmBench is a small step inside a larger PyRIT setup. PyRIT installs with pip, supports Python 3.10 up to but not including 3.15, and the documentation recommends Python 3.13. The real effort sits around the dataset: configuring a target, choosing a scorer, deciding which objectives reach the target, and storing results in memory. Teams without prior PyRIT experience should plan time to read the Foundry and AIRT scenario documentation and run a small pilot before a full sweep. Confirm your Python version and environment policy before starting.

What costs should we expect when running HarmBench with PyRIT?

Most of the cost is variable and comes from three sources. Model calls to your target are charged by whoever hosts the model, and each objective can produce multi-turn exchanges that multiply that volume. Scorer calls add more, because LLM-based scorers or Azure AI Content Safety calls are billed separately from the target. Staff time covers setup, review of flagged responses, and triage of findings. Sample size is the main lever: the max dataset size setting limits how many objectives run, so cost scales with it. Ask any partner for a quote that separates these three lines and states which are one-time and which recur on each run.

Do we need a partner to run HarmBench with PyRIT?

You do not need a partner to run HarmBench, because PyRIT is open source and the dataset is available to any team. A partner becomes useful when the work needs test design, target integration, evidence for an assessment, or a repeatable pipeline that your staff cannot maintain. Consider a partner if your team lacks time to review results, needs independent testing of an application you built, or must prepare documentation for a compliance review. Whichever route you take, agree in writing who reviews findings and who owns the retest.

How long does a first HarmBench run take?

Duration depends on the sample size you set with max dataset size, the number of turns each attack allows, the response time of your target, and how many scorer calls each response triggers. A small illustrative sample against a fast target finishes far sooner than a full sweep against a slow, rate-limited endpoint. Run a small sample first to measure response times and error rates, then scale up. Plan extra time for reviewing results, because scored output still needs a human to confirm which hits are real. No general duration figure is supplied, so measure it in your own environment.

What does the work need from our team?

Expect to provide four things. First, access to a target: an endpoint or application that PyRIT can reach, with a clear description of its intended use. Second, credentials stored in ~/.pyrit/.env or a secrets store you control, scoped to the minimum permissions the test requires. Third, approved test windows, because attack traffic can trigger alerts, rate limits or costs on production systems. Fourth, a named reviewer who can judge flagged responses. Confirm with your security and platform owners whether testing against a staging copy is acceptable before you begin.

When is HarmBench enough, and when do we need custom objectives?

HarmBench works well as a broad, standard baseline that many teams can compare against. It is the default dataset for PyRIT's Foundry RedTeamAgent scenario and the objective dataset in the Jailbreak scenario example. Use it when you need general coverage and a common reference point. Write custom objectives when your application has specific harms, such as leaking account data, giving regulated advice, or acting on tool calls in your own workflows. Many teams run HarmBench first to establish a baseline, then add application-specific objectives in a YAML seed file. Confirm that your harm list is documented before deciding which set to rely on.

Security and operational considerations for HarmBench runs

A HarmBench run sends harmful objectives to a target, stores every response and spends money on each call. The cards below cover the parts of that setup a security or platform team should review before the first run, and what to confirm in the PyRIT version you deploy.

Credentials in the ~/.pyrit directory

PyRIT reads provider credentials from ~/.pyrit/.env and settings from ~/.pyrit/.pyrit_conf. On a shared runner or a developer laptop, that file can expose keys for the target model as well as any scorer model. Confirm who can read the home directory on each host, keep the file out of source control and CI logs, and use a separate key with a spending limit for red teaming so a leaked key cannot reach production budgets.

Run memory in SQLite or Azure SQL

PyRIT stores conversations, scores and results in SQLite or Azure SQL. The memory file holds the full text of every harmful prompt and model reply, so it is as sensitive as the test data itself. Set file permissions on any SQLite database, restrict database roles on Azure SQL, decide who may query or export memory, and set a retention rule that deletes runs your team no longer needs.

AIRT scenarios

Keeping harmful outputs out of shared logs

HarmBench objectives are written to elicit unsafe content, so model replies can contain instructions or material that should not appear in chat channels, ticket attachments or CI dashboards. Configure logging so that console and pipeline output shows run status and scores, not full transcripts. Export conversations only to a restricted location, and tell reviewers where the transcripts live before a run starts.

Rate limits and cost control

Each HarmBench objective can trigger several calls to the target and to an LLM scorer, and a sampled run multiplies that. Before starting, ask the target provider for its rate limits and quota, set a concurrency limit in PyRIT, and estimate call volume from the number of objectives, the attack strategy and the scorer. Stop the run if error rates or spend exceed the agreed limit, because retries can quietly multiply cost.

Reporting PyRIT vulnerabilities privately

If a test shows that PyRIT itself mishandles credentials, memory or output, report it privately rather than in a public issue. The project's security policy directs reports to the Microsoft Security Response Center. Keep a copy of the minimal reproduction in your own restricted tracker, and do not paste harmful model output into the report beyond what the maintainers need to reproduce the issue.

PyRIT project

Official PyRIT documentation for scenarios

The next read for anyone running HarmBench through PyRIT is the official scenario documentation in the PyRIT 1.1.0 docs. The Foundry Scenarios page explains how the Foundry RedTeamAgent scenario uses HarmBench as its default dataset, and the AIRT Scenarios page covers the AIRT scenario family, including the Jailbreak scenario that takes HarmBench-style objectives as its example input. Read both before you change any dataset parameter, because the exact option names and defaults are what your run depends on.

Before you trust any result, check the version you installed. PyRIT ships breaking changes between releases, and the documentation you read has to match the package in your environment. The current docs are labeled 1.1.0, and the PyPI package (pyrit) and the GitHub releases page list what each version contains. Confirm the installed version with pip, then compare the scenario parameters on the page against the code. Record the version and the documentation URL in your test notes so an auditor or colleague can reproduce the same run later.

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.