Repository navigation
FEAT: Add HarmEval dataset loader - #2794
Merged
Roman Lutz (romanlutz) merged 3 commits intoSep 23, 2026
Merged
Conversation
Adds a remote seed dataset loader for SoftMINER-Group/HarmEval, the ~550-query safety benchmark released with SafeInfer (AAAI-2025), covering the 11 prohibited-use categories from OpenAI's and Meta's usage policies. The dataset is gated on HuggingFace, so the loader takes a `token` kwarg that falls back to HUGGINGFACE_TOKEN and forwards it to the HF fetch helper, and the class docstring records the gate terms: the metadata tags the dataset Apache-2.0, but access additionally requires attesting to non-commercial use only and to not running experiments that harm human subjects. No data is vendored into the repository. Rows are emitted as SeedObjective, matching _CategoricalHarmfulQADataset, which is built against the same OpenAI/Meta taxonomy. HarmEval's Topic labels are exposed as the module-level HarmEvalTopic enum for filtering, preserved verbatim in per-seed metadata, and mapped onto PyRIT's canonical harm categories through HARM_CATEGORY_ALIAS_OVERRIDES; five of the eleven topics resolve to OTHER without it. Issue microsoft#2770 notes the column names were never verified against the gated data, so the loader raises explicitly when a row lacks Question/Topic instead of silently producing an empty dataset.
…terms Storing the caller's list by reference let a later mutation change what the loader filters on. And the docstring asserted which of the two licence statements governs; it now records both and leaves that to the reader.
Roman Lutz (romanlutz)
approved these changes
Sep 23, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Closes #2770. Adds a remote seed dataset loader for SoftMINER-Group/HarmEval, the ~550-query benchmark released with SafeInfer (AAAI-2025), covering the 11 prohibited-use categories from OpenAI's and Meta's usage policies.
Gap
No loader existed. On
3116a2d,grep -ril harmeval . --exclude-dir=.gitreturned nothing, andSeedDatasetProvider.get_all_dataset_names_async()returned 115 names with noharmeval.Fix
pyrit/datasets/seed_datasets/remote/harmeval_dataset.py_HarmEvalDataset(_RemoteDatasetLoader)+ module-levelHarmEvalTopicenum (11 values, verbatim upstreamTopicstrings)pyrit/datasets/seed_datasets/remote/__init__.py_materialize_builtin_providers(seed_dataset_provider.py:358) walks__all__, so these are what make the loader discoverabletests/end_to_end/test_all_datasets.py:69_HarmEvalDatasetadded to_HF_GATED_PROVIDERSso the daily E2E run skips instead of failing without a tokendoc/references.bib,doc/bibliography.md@banerjee2025safeinferdoc/code/datasets/1_loading_datasets.{py,ipynb}'harmeval'in the dataset-name output celltests/unit/datasets/test_harmeval_dataset.pyGating. Constructor takes
token: str | None = None, falls back toHUGGINGFACE_TOKEN, and forwards it to_fetch_from_huggingface_async, per the_SorryBenchDataset/_VLGuardDatasetpattern.Usage terms (the issue asks for this explicitly). The HF metadata tags the dataset
apache-2.0, but access isgated: autoand the request form requires attesting "I agree to use this dataset for non-commercial use ONLY" and agreeing not to run experiments that harm human subjects. The class docstring records both and says to treat the gate terms as binding rather than reading the Apache-2.0 tag as unrestricted use. Nothing is vendored into the repo.Seed type.
SeedObjective, matching_CategoricalHarmfulQADataset— same lab, same 550-question shape, same OpenAI/Meta 11-category taxonomy.Harm-category mapping.
HARM_CATEGORY_ALIAS_OVERRIDESis load-bearing: 5 of the 11 topics (Child Abuse Content,Economic Harm,Hate/Harass/Violence,Privacy Violation Activity,Tailored Financial Advice) resolve toOTHERwithout it. The map mirrors_CategoricalHarmfulQADataset's (categorical_harmful_qa_dataset.py:111) for every shared label so seeds from the two datasets stay filterable together. Source labels are preserved verbatim inmetadata["topic"].Schema guard. The issue notes the #429 column names were never verified. With
.get()a renamed column would silently produce an empty dataset and a misleading "check your filter criteria" error, so the loader raises naming the missing column and the keys the row actually has.Not in scope
HF_REVISIONpin — only_FortressDatasetpins one; the other 61 loaders don't. For the record, the sha I inspected isd1f62d8c8a42b919d7466fcd1896dc9cdb8134c3. Happy to add it.Economic Harmmapping left as is.references.bibentry appended at EOF rather than inserted alphabetically: the file isn't alphabetical in any section (FORTRESS putknight2025fortressbetweenjiang2025sosbenchandsouly2024strongreject), and appending avoids colliding with FIX Correct SemGuard citation and CodeAttack source metadata #2790, which edits the SemGuard entry mid-file.bibliography.mdis alphabetical and the key is inserted correctly there.Tests and Documentation
38 tests, all mocked, no live HF call. Everything
datasets.instructions.mdasks for (dataset_name, happy path, each of the 11 filter values, empty-after-filter, invalid enum, token forwarding x3), plus: no topic may standardize toOTHER; the five overridden mappings are pinned; schema drift raises; and the loader actually reaches the catalog.E2E:
pytest tests/end_to_end/test_all_datasets.py --collect-onlycollectstest_fetch_dataset[_HarmEvalDataset-_HarmEvalDataset]; running it with no token gives1 skipped — HUGGINGFACE_TOKEN not set (required for gated dataset used by _HarmEvalDataset).Pre-commit local hooks run individually:
validate_docs,check_async_suffix,check_no_rest_roles,sanitize_notebook_paths,strip_notebook_progress_bars,strip_py_kernelspecall rc=0;nbstripout --keep-output --extra-keys=metadata.kernelspecleaves the notebook byte-identical.doc/references.bibparses to 101 entries with no duplicate keys.The notebook's dataset-name cell was edited inline against the real
get_all_dataset_names_async()output rather than by eye — the list is sorted and'harmeval'lands between'harmbench_multimodal'and'harmful_qa'.I also ran 13 deliberate mutations of the loader (wrong split, dropped token forwarding, inverted filter, deleted alias override, deleted schema guard, removed the
__init__.pyregistration, etc.); all 13 fail the suite. Two survived a first pass and the tests were tightened:SeedDataset's own validator also raises "SeedDataset cannot be empty", so that assertion now matches the loader'sHarmEval filter: topics=[...]message; and the discovery test now asserts"_HarmEvalDataset" in remote.__all__, because importing the loader module directly registers the class via__init_subclass__and masked the missing export.Not verified — needs someone with dataset access
datasets.instructions.md:123asks for a one-time sanity check against the real data before opening the PR. I could not do this: the dataset is gated and I have no accepted access (curlon the CSV returns 401).What I verified instead: the HF API metadata (single file
Safe_Infer_Final_Dataset_550_Without_Answer.csv, 64,174 bytes,gated: auto, license and gate terms as quoted); the authors' own README, which states the 11 categories, the ~550 queries and the GPT-4 + Perspective-API (>= 0.7) filtering; and columnsQuestion/Topic+ splittrain+ the exact 11 topic strings, agreed on by four independent readers of the real data — GuardBench, guard-eval-harness (which pins the same sha), a PrimeIntellect environment, and this preprocessing script.Please run
await _HarmEvalDataset().fetch_dataset_async()once with a token before merging. The residual risk is cosmetic drift in aTopicstring (which would land that row inOTHERrather than fail) or an off count.Two unrelated things noticed
Not fixed here; happy to send separate PRs.
doc/code/datasets/1_loading_datasets.ipynbis already stale on main: the output cell lists 112 names, runtime returns 116 (before this PR, 115). Missing:garak_divergence,prompt_inject_contexts,prompt_inject_techniques..github/instructions/datasets.instructions.mdnames the helper_fetch_from_huggingfaceat lines 38, 45, 108 and 117; the real method is_fetch_from_huggingface_async(remote_dataset_loader.py:329). Following the file literally produces a test that patches an attribute that doesn't exist.