-
Notifications
You must be signed in to change notification settings - Fork 779
FEAT: Add StrongREJECT seed dataset loader #1800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
romanlutz
merged 3 commits into
microsoft:main
from
romanlutz:romanlutz/plan-strongreject-benchmark
May 30, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
pyrit/datasets/seed_datasets/remote/strong_reject_dataset.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT license. | ||
|
|
||
| from typing import Literal | ||
|
|
||
| from pyrit.datasets.seed_datasets.remote.remote_dataset_loader import ( | ||
| _RemoteDatasetLoader, | ||
| ) | ||
| from pyrit.models import SeedDataset, SeedObjective | ||
|
|
||
|
|
||
| class _StrongRejectDataset(_RemoteDatasetLoader): | ||
| """ | ||
| Loader for the StrongREJECT dataset. | ||
|
|
||
| StrongREJECT is a refusal-robustness benchmark of 313 forbidden-behavior | ||
| prompts spanning six harm categories. Each row also carries a ``source`` | ||
| column attributing prompts inherited from prior datasets (AdvBench, DAN, | ||
| HarmfulQ, MaliciousInstruct, MasterKey, "Jailbreaking via Prompt | ||
| Engineering", and the OpenAI System Card), with custom-authored StrongREJECT | ||
| prompts marked ``source="custom"``. | ||
|
|
||
| The companion 60-prompt subset published upstream | ||
| (``strongreject_small_dataset.csv``) is intentionally not exposed: it is a | ||
| strict prompt-subset of the full set with hand-edited metadata (three rows | ||
| have their ``source`` rewritten to ``"custom"`` even though the same prompts | ||
| are attributed to AdvBench/DAN in the full CSV). Users who want a smaller | ||
| balanced sample can post-filter this loader at runtime. | ||
|
|
||
| Reference: [@souly2024strongreject] | ||
| """ | ||
|
|
||
| # Metadata | ||
| harm_categories: list[str] = [ | ||
| "disinformation and deception", | ||
| "hate, harassment and discrimination", | ||
| "illegal goods and services", | ||
| "non-violent crimes", | ||
| "sexual content", | ||
| "violence", | ||
| ] | ||
| modalities: list[str] = ["text"] | ||
| size: str = "medium" # 313 seeds | ||
| tags: set[str] = {"jailbreak", "safety"} | ||
|
|
||
| def __init__( | ||
| self, | ||
| *, | ||
| source: str = ( | ||
| "https://raw.githubusercontent.com/alexandrasouly/strongreject/" | ||
| "3432b2d696b428f242bd507df96d80f686571d5e/strongreject_dataset/strongreject_dataset.csv" | ||
| ), | ||
| source_type: Literal["public_url", "file"] = "public_url", | ||
| ) -> None: | ||
| """ | ||
| Initialize the StrongREJECT dataset loader. | ||
|
|
||
| Args: | ||
| source (str): URL to the StrongREJECT CSV file. Defaults to the pinned-commit raw URL | ||
| on the upstream GitHub repository. | ||
| source_type (Literal["public_url", "file"]): The type of source ('public_url' or 'file'). | ||
| """ | ||
| self.source = source | ||
| self.source_type: Literal["public_url", "file"] = source_type | ||
|
|
||
| @property | ||
| def dataset_name(self) -> str: | ||
| """Return the dataset name.""" | ||
| return "strong_reject" | ||
|
|
||
| async def fetch_dataset_async(self, *, cache: bool = True) -> SeedDataset: | ||
| """ | ||
| Fetch the StrongREJECT dataset and return it as a SeedDataset. | ||
|
|
||
| Args: | ||
| cache (bool): Whether to cache the fetched dataset. Defaults to True. | ||
|
|
||
| Returns: | ||
| SeedDataset: A SeedDataset containing the StrongREJECT forbidden behaviors. | ||
|
|
||
| Raises: | ||
| ValueError: If any row is missing required keys or the dataset is empty. | ||
| """ | ||
| required_keys = {"forbidden_prompt", "category", "source"} | ||
|
|
||
| examples = self._fetch_from_url( | ||
| source=self.source, | ||
| source_type=self.source_type, | ||
| cache=cache, | ||
| ) | ||
|
|
||
| authors = [ | ||
| "Alexandra Souly", | ||
| "Qingyuan Lu", | ||
| "Dillon Bowen", | ||
| "Tu Trinh", | ||
| "Elvis Hsieh", | ||
| "Sana Pandey", | ||
| "Pieter Abbeel", | ||
| "Justin Svegliato", | ||
| "Scott Emmons", | ||
| "Olivia Watkins", | ||
| "Sam Toyer", | ||
| ] | ||
|
|
||
| seeds = [] | ||
| for example in examples: | ||
| missing_keys = required_keys - example.keys() | ||
| if missing_keys: | ||
| raise ValueError(f"Missing keys in example: {', '.join(sorted(missing_keys))}") | ||
|
|
||
| seeds.append( | ||
| SeedObjective( | ||
| value=example["forbidden_prompt"], | ||
| name="StrongREJECT forbidden behavior", | ||
| dataset_name=self.dataset_name, | ||
| harm_categories=[example["category"]], | ||
| description=( | ||
| "A StrongREJECT forbidden-behavior prompt covering one of six harm categories " | ||
| "(disinformation, hate/harassment/discrimination, illegal goods and services, " | ||
| "non-violent crimes, sexual content, violence). The companion StrongREJECT " | ||
| "rubric scores responses on refusal x convincingness x specificity." | ||
| ), | ||
| authors=authors, | ||
| groups=["UC Berkeley"], | ||
| source="https://github.com/alexandrasouly/strongreject", | ||
| metadata={"strong_reject_source": example["source"]}, | ||
| ) | ||
| ) | ||
|
|
||
| if not seeds: | ||
| raise ValueError("SeedDataset cannot be empty. Check your filter criteria.") | ||
|
|
||
| return SeedDataset(seeds=seeds, dataset_name=self.dataset_name) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.