Testing over-refusal with XSTest in PyRIT: why refusals need measuring too
If your team has red teamed an assistant for harmful compliance and now needs to know whether safety tuning or filters block legitimate requests, run an over-refusal test alongside your attack suite. A model that refuses everything passes an attack test, so refusal rates on safe prompts are the measurement that keeps the attack results honest. Over-refusal is a failure mode you can measure, not a side effect you can assume away. XSTest-style datasets contain safe prompts that look unsafe on the surface, such as questions about how to kill a Python process or which household chemicals should never be mixed. A well-behaved assistant should answer these. PyRIT can load XSTest and CoCoNot as research datasets, as described in its built-in dataset loading guide, so the prompts come from a maintained source rather than a list your team wrote under deadline.
Teams need this test when they change the safety layer: after a model swap, a fine-tune, a new system prompt, or a new input or output filter goes live. Each of these can move the balance toward refusal, and an attack-only report will not show it. Run the same safe prompts before and after the change, and score the responses with PyRIT's refusal scorer, which is described in the true/false scorers reference. Confirm in your own environment that the scorer's refusal judgment matches your product's definition of a refusal, because a partial answer that adds disclaimers may or may not count. Record the refusal rate on safe prompts next to your attack success rate, so a fix that cuts harmful compliance by refusing more is visible as a trade.
An over-refusal result does not prove that the assistant is safe, and a low refusal rate does not prove that it is useful. XSTest-style sets cover a fixed set of safe-but-suspicious categories, so they miss the legitimate requests specific to your users, such as clinical questions in a health product or security questions from analysts. They also say nothing about whether a refusal is well worded or whether harmful requests are still blocked. Treat the result as one input to a decision on thresholds and filter tuning, and ask your vendor or internal model team which thresholds they plan to hold the assistant to before the test runs.
How an over-refusal run moves from dataset to decision
The run starts with a benign dataset such as XSTest, loaded through PyRIT's built-in dataset loader or a custom file. Each prompt goes through a PyRIT target, which is the model or application endpoint under test, and the response is passed to a refusal scorer. Every prompt, response and score is kept in PyRIT memory so the refusal rate can be traced back to individual items. The final decision compares that over-refusal rate with the attack success rate from separate harmful-prompt runs, so a fix that reduces refusals is not accepted if it also lets more attacks through.
Benign prompts flow through PyRIT and are compared with separate harmful-prompt results before a decision.
Which dataset and scorer configuration fits which test goal
This table compares dataset sources, refusal scorer types and run shapes for over-refusal testing, with the cost, judge bias and coverage trade-off of each. Read each row as a starting configuration, then confirm the scorer behavior on a sample from your own application before relying on the results.
| Configuration | Best fit | Main trade-off | When to choose it |
|---|---|---|---|
| XSTest-style safe prompts | Measuring refusals of clearly legitimate prompts that look superficially risky | Prompts are generic, so they may not match your product's real user requests | Early baseline across many assistants or model versions |
| CoCoNot prompts | Testing refusals on requests a model should decline for context reasons, to check it does not refuse everything | Mixed purpose, so scores need careful reading against the expected behavior | When you need a second benchmark that checks both over- and under-refusal |
| Your own business requests | Measuring refusals on the tasks your users actually send | Needs domain expert writing and review, so the team carries the effort | Before a release or rollout where the assistant must serve specific workflows |
| LLM judge refusal scorer | Detecting soft refusals, partial answers and redirects | Judge model adds cost per response and may share biases with the target | Free-text answers where wording varies widely |
| Azure AI Content Safety scorer | Checking harmful content in responses alongside refusal behavior | Designed for harm categories, so it may not reliably flag a plain refusal | When you also need harm classification in the same run |
| Custom string or rule logic | Fast, cheap detection of fixed refusal phrases in known response formats | Misses paraphrased refusals and can count polite non-answers as compliance | Deterministic checks in CI or when the target returns short, fixed refusal text |
| Single-turn run | Testing whether one legitimate prompt is refused on its own | Does not show refusals that appear only after conversational context builds | First pass across a full dataset at low cost |
| Multi-turn run | Testing whether refusals appear during a realistic conversation or after follow-up clarification | Higher cost per objective and harder scorer calibration across turns | After single-turn results show refusals that may depend on context |
Setting up an XSTest over-refusal run in PyRIT
This sequence takes a team from a clean Python environment to a verified XSTest over-refusal run against their own assistant. The output is a small, hand-checked baseline showing whether refusal labels are trustworthy before any full run is scheduled.
Install PyRIT on a supported Python version
Create a dedicated virtual environment and install 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 pick that version if your platform team has it available. Done when the package imports cleanly in a Python shell and the installed version matches the release you intend to pin, such as v1.1.0 or a later release you have reviewed.
Configure credentials and settings files
Place the credentials for your target and scorer endpoints in ~/.pyrit/.env, and put run settings such as memory and default targets in ~/.pyrit/.pyrit_conf. Keep the .env file out of version control and restrict its file permissions to the account that runs the tests. Done when a short test script reads the expected settings without printing any secret values to the console or logs.
Connect the assistant under test as a target
Define the target that represents the assistant you want to measure, using a built-in target type for a supported model endpoint or a custom HTTP or WebSocket target for your own application. Confirm with the assistant's owner which system prompt, safety filter and tool configuration the target uses, because over-refusal results only describe that exact setup. Done when a single test message sent through the target returns a response that is stored in PyRIT memory.
Load XSTest with the built-in dataset loader
Use PyRIT's built-in dataset loader to load XSTest, which is among the research datasets PyRIT can load. Check the loaded prompts against the dataset's own documentation so you know which entries are safe prompts that should be answered and which are contrast prompts that look unsafe but are legitimate. Done when the loader returns the expected number of prompts and you have recorded the dataset version and any filter you applied.
Configure the refusal scorer
Attach a true/false refusal scorer to the attack so each response is labeled as a refusal or a compliance. Review how the scorer is defined in the PyRIT scoring documentation and decide whether a judge model, custom logic or both will label responses, since that choice affects accuracy. Done when the scorer returns a boolean label for a sample of known refusal and known compliance responses you wrote by hand.
Run a small sample before the full dataset
Run the attack on a small, fixed sample of XSTest prompts, keeping concurrency and retries low so errors are easy to trace. Review the stored conversations and scorer labels for each item, noting any target errors, timeouts or empty responses that should not count as refusals. Done when the sample run completes without unexplained failures and every result is saved in memory with its prompt, response and label.
Verify labels against a hand-checked set
Have a reviewer who did not configure the scorer label a fixed set of responses as refusal, partial answer or full compliance, without seeing the scorer output first. Compare the reviewer labels with the scorer labels, record disagreements, and decide whether the scorer needs a different prompt, judge model or rule before the full run. Done when the disagreement list is reviewed and the agreement rate on the hand-checked set is recorded as the baseline for the full over-refusal measurement.
Balancing over-refusal against attack success
Product owners read the over-refusal result as a measure of how often the assistant turns down requests that a reasonable user would consider legitimate. A benign dataset such as XSTest-style prompts shows where the assistant refuses safe requests that merely resemble harmful ones, for example questions about medication doses, security concepts or fiction with dark themes. The refusal scorer classifies each response, and the refusal rate on the benign set becomes the figure to track against the product's intended behavior.
- Refusal rate on benign prompts: This is the headline number. Ask which categories of prompt the refusals cluster in, not only the overall percentage.
- Borderline categories: Review a sample of refused responses to confirm the refusal was actually unwarranted before treating it as a defect.
- Scorer agreement: Check how the refusal scorer labels partial answers, hedged answers and answers that refuse only part of a request.
- Trend across versions: Compare the rate between model or filter versions using the same dataset and settings.
- Product impact: Map refused categories to user journeys so the cost of each refusal is visible.
Before you act on any refusal rate, confirm the target configuration, system prompt and filter settings match the security run.
Security teams read attack success. They run harmful objectives through the same target and measure how often the assistant produces disallowed content. A lower attack success rate is good only if the assistant still answers legitimate requests, so this tab must be read beside the over-refusal result rather than alone. Attack success depends heavily on the attack strategy, the converters and the scorer, so a single number says little without those details.
- Objective set: Record which harmful dataset and sample size produced the success rate.
- Attack strategy: Single-turn and multi-turn attacks can produce very different results against the same target.
- Scorer definition: State what counts as success and which scorer decided it.
- Failure review: Read successful attacks to find which filter or instruction failed.
- Retest after change: Repeat the same attack set after any tuning or filter change to confirm the gain.
Before publishing a success rate, confirm the same target configuration was used for the benign run.
Compliance reviewers need both results from one controlled configuration, because an assessor can ask whether the organization reduced harmful output without making the assistant unusable for legitimate work. DeployOpen does not issue audit reports or certifications. It prepares the test systems and evidence that independent assessors review. Reviewers should be able to trace each figure to the run that produced it.
- Shared configuration record: Keep the model version, system prompt, filter settings and PyRIT version identical for both runs and record them with the results.
- Side-by-side reporting: Present over-refusal and attack success in one table with the same date range and target.
- Known trade-offs: Document where a stricter filter raised refusals and what risk acceptance decision was made.
- Retained memory: Keep conversations and scores so a reviewer can follow any figure back to its source.
- Change control: Tie each change in filters or prompts to a new paired run.
Ask your assessor which evidence format they accept and confirm it before the first run.
Security and operational considerations for over-refusal testing
Over-refusal tests send large batches of benign and borderline prompts to a live assistant, store every response, and depend on a judge to label refusals. Each of the cards below is a place where the test can leak data, run up cost, or report a false result, so settle them before the first run.
Credentials in the local environment file
PyRIT reads target credentials from ~/.pyrit/.env, so the file sits in the home directory of whichever account runs the test. Confirm that only the test operator can read it, that it is excluded from version control, and that keys for the assistant under test are scoped to a test deployment rather than production. Rotate them after the test if the runner is shared. A benign dataset run with a leaked key is still a leaked key.
Who can read stored responses
PyRIT memory keeps every prompt and response from an over-refusal run in SQLite or Azure SQL. Benign prompts often touch sensitive topics such as medicine, finance or security, so the stored transcripts can be as sensitive as production logs. Decide who can query the database, where the file or server lives, how long records are kept, and whether the store is backed up or deleted at the end of the engagement.
Rate limits and cost on the target
Over-refusal suites can send thousands of requests, and a paid model endpoint bills for each one, while a shared service may throttle the test team. Before the run, ask the target owner for the request limit, the token budget, and a test window that will not affect real users. Cap concurrency and retries in the run settings so a failing endpoint does not multiply the bill.
Scorer reliability and judge bias
The refusal scorer decides which responses count as over-refusals, so its errors become your metrics. An LLM judge may mark polite partial answers as refusals, or miss refusals phrased as hedged redirects. Hand-label a sample of responses, compare the judge against those labels, and report the disagreement rate alongside the headline number. Use a judge from a different model family than the assistant when possible.
True/False scorersKeeping benign and harmful sets apart
A single run that mixes XSTest-style safe prompts with harmful objectives blurs two numbers: how often the assistant wrongly refuses and how often it wrongly complies. Store the benign and harmful datasets in separate files with distinct labels, run them as separate scenarios, and report them as separate results. This keeps the over-refusal rate from being diluted by attack prompts and keeps attack success rates from being inflated by benign items.
Vulnerability reports for PyRIT itself
If testing shows that PyRIT or its configuration exposes data or credentials, report it privately rather than in a public issue. The project's security policy routes vulnerability reports through the Microsoft Security Response Center. Keep the reproduction steps inside the team until a fix is available, and record the report in your own findings log so the issue is tracked alongside the assistant results.
PyRIT on GitHubQuestions teams ask before testing over-refusal with XSTest
How much effort does a first over-refusal run take?
A first run takes more effort than the script itself, because most of the work sits in three places: getting a working connection to the assistant under test, choosing and configuring a refusal scorer, and reviewing a sample of its verdicts by hand. XSTest-style datasets are built to include safe prompts that look risky, so a scorer that misreads a helpful answer as a refusal will distort the result. Budget time for a human reviewer to label a sample before trusting the numbers. The PyRIT True/False scorers documentation explains how scorer output is structured and where to check it. Effort rises with the number of target endpoints, the number of languages or product modes you need to cover, and how strict your review process must be.
Can our team run over-refusal tests alone using the documentation?
Yes, a team with Python experience and access to its own model or application can run these tests from the PyRIT documentation, provided someone owns the target connection, the scorer setup and the review of results. PyRIT lists XSTest and CoCoNot among the research datasets it can load, so dataset loading is documented rather than custom work. The harder parts are judgment calls: which refusal criteria count as a failure for your product, how to handle partial answers, and whether a refusal is appropriate for your risk profile. Teams without an AI security or evaluation owner often find those decisions take longer than the tooling. A partner can take that work on under a written scope if you want it.
What do we need to provide before a test can start?
You need four things ready before work starts: a reachable target endpoint for the assistant or application under test, credentials that let the test client call it in a non-production or approved environment, a description of the product behavior you want to protect, and a named reviewer who can check scorer verdicts. The endpoint may be an API, a custom HTTP or WebSocket app, or a web chat interface, and each needs a different connection approach. Credentials belong in the environment file PyRIT reads, not in dataset files or reports. Ask your security team to confirm which environments may receive adversarial traffic and where results may be stored.
How long does an over-refusal run take, and what sets that?
The run time depends on how many prompts you send, how many times each prompt is repeated, the response latency of the target, and how long your reviewers need to check verdicts. Dataset size is set by the dataset and any sampling limit you apply, so ask for the sample size and the review sample in the written scope rather than relying on a general figure. Rate limits on your model provider or application often become the constraint before compute does. Plan a separate window for reviewing results and for rerunning after any change to the scorer or the target configuration.
Can we get a partner's fee without a written scope?
Not reliably. A fee depends on the target types, the number of datasets and languages, the scorer and review approach, reporting requirements and whether results feed a compliance review. DeployOpen does not publish a price list, and it provides a quote from a written scope that sets deliverables and timelines in advance. To prepare a request, list your target endpoints, the product behaviors you care about, the datasets you want to include, who will review verdicts, and what evidence your auditors or customers expect. Ask any vendor to separate one-time setup from recurring runs and retesting after model or prompt changes.
How do over-refusal results and attack success rates fit together in an audit?
Present them together, as two sides of one tradeoff: over-refusal results show whether the assistant refuses legitimate requests, and attack success results show whether it complies with harmful ones. A change that reduces attack success by making the model refuse more may increase over-refusal, so an auditor needs both measurements from the same model version, scorer configuration and date. Keep the dataset version, scorer settings, reviewer sample and memory records together so each figure can be traced. PyRIT stores conversations and results in SQLite or Azure SQL, which supports that traceability. Confirm with your auditor which evidence format they accept, since the framework does not produce audit conclusions.
How DeployOpen scopes and delivers over-refusal testing
DeployOpen approaches over-refusal testing as a fixed-scope engagement: the refusal behavior of your assistant is measured against a benign and a harmful prompt set, then the results are turned into fixes you can verify. The work runs inside your own infrastructure, with PyRIT, its datasets and the scoring setup documented so your team can rerun it.
How we scope
- Agree in writing which assistant, model endpoint or application wrapper is under test and which configuration is in scope.
- Define which legitimate request categories count as over-refusal for your product, such as medical, security or legal questions.
- Confirm which XSTest-style and harmful objective datasets apply, and how the two result sets will be compared.
How we build
- Configure the PyRIT target, the prompt sets and the refusal scorer in your environment, with credentials kept out of source files.
- Run a baseline over benign and harmful prompts, recording refusals, partial answers and completed answers for each category.
- Test any proposed filter or safety tuning change against the same sets so the trade-off between refusals and attack success is visible.
How we hand over
- Deliver the prompt sets, scorer configuration and run scripts as versioned files your team owns and can rerun.
- Provide a findings report with over-refusal rates by category, attack success results and recommended threshold or prompt changes.
- Document how results were stored in PyRIT memory so reviewers can trace each conclusion back to the recorded conversation.
How we support
- Ongoing support, upgrades and continuous testing are available as a retainer, for example when you change models or filters.
- Retest after fixes are applied and confirm which over-refusal categories have moved and which have not.
- Ask any provider for the scope, deliverables and written terms before work starts, since no price list is published and a quote follows from the scope.

