Skip to content

FEAT: Add HarmEval dataset loader - #2794

Merged
Roman Lutz (romanlutz) merged 3 commits into
microsoft:mainfrom
v0ropaev:feat/harmeval-dataset
Sep 23, 2026
Merged

Roman Lutz (romanlutz) merged 3 commits into
microsoft:mainfrom
v0ropaev:feat/harmeval-dataset

Conversation

@v0ropaev

Copy link
Copy Markdown
Contributor

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=.git returned nothing, and SeedDatasetProvider.get_all_dataset_names_async() returned 115 names with no harmeval.

Fix

Surface Change
pyrit/datasets/seed_datasets/remote/harmeval_dataset.py New _HarmEvalDataset(_RemoteDatasetLoader) + module-level HarmEvalTopic enum (11 values, verbatim upstream Topic strings)
pyrit/datasets/seed_datasets/remote/__init__.py TYPE_CHECKING import + both lazy exports; _materialize_builtin_providers (seed_dataset_provider.py:358) walks __all__, so these are what make the loader discoverable
tests/end_to_end/test_all_datasets.py:69 _HarmEvalDataset added to _HF_GATED_PROVIDERS so the daily E2E run skips instead of failing without a token
doc/references.bib, doc/bibliography.md @banerjee2025safeinfer
doc/code/datasets/1_loading_datasets.{py,ipynb} HarmEval in the prose list and 'harmeval' in the dataset-name output cell
tests/unit/datasets/test_harmeval_dataset.py 38 mocked tests

Gating. Constructor takes token: str | None = None, falls back to HUGGINGFACE_TOKEN, and forwards it to _fetch_from_huggingface_async, per the _SorryBenchDataset / _VLGuardDataset pattern.

Usage terms (the issue asks for this explicitly). The HF metadata tags the dataset apache-2.0, but access is gated: auto and 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_OVERRIDES is load-bearing: 5 of the 11 topics (Child Abuse Content, Economic Harm, Hate/Harass/Violence, Privacy Violation Activity, Tailored Financial Advice) resolve to OTHER without 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 in metadata["topic"].

One question for reviewers: CatQA maps Economic Harm to [SCAMS, DECEPTION], and I followed it. The OpenAI policy category it derives from is MLM / gambling / payday lending / automated eligibility, which would argue for [MLM, GAMBLING, LENDING, FINANCIAL_ELIGIBILITY]. I kept the existing precedent rather than invent a mapping for rows I can't read (gated), and didn't touch CatQA. Say the word and I'll change both.

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

  • SafeInfer's decoding-time alignment method (per the issue).
  • No HF_REVISION pin — only _FortressDataset pins one; the other 61 loaders don't. For the record, the sha I inspected is d1f62d8c8a42b919d7466fcd1896dc9cdb8134c3. Happy to add it.
  • CatQA's Economic Harm mapping left as is.
  • references.bib entry appended at EOF rather than inserted alphabetically: the file isn't alphabetical in any section (FORTRESS put knight2025fortress between jiang2025sosbench and souly2024strongreject), and appending avoids colliding with FIX Correct SemGuard citation and CodeAttack source metadata #2790, which edits the SemGuard entry mid-file. bibliography.md is alphabetical and the key is inserted correctly there.

Tests and Documentation

38 tests, all mocked, no live HF call. Everything datasets.instructions.md asks for (dataset_name, happy path, each of the 11 filter values, empty-after-filter, invalid enum, token forwarding x3), plus: no topic may standardize to OTHER; the five overridden mappings are pinned; schema drift raises; and the loader actually reaches the catalog.

pytest tests/unit/datasets/test_harmeval_dataset.py -q   ->  38 passed in 1.15s
pytest tests/unit/datasets -q                            ->  4820 passed (4781 on main; +39)
ruff format --check pyrit tests doc                      ->  1640 files already formatted
ruff check pyrit tests                                   ->  All checks passed
ty check pyrit tests/unit                                ->  122 diagnostics — identical count on an
                                                             unmodified checkout; none mention harmeval

E2E: pytest tests/end_to_end/test_all_datasets.py --collect-only collects test_fetch_dataset[_HarmEvalDataset-_HarmEvalDataset]; running it with no token gives 1 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_kernelspec all rc=0; nbstripout --keep-output --extra-keys=metadata.kernelspec leaves the notebook byte-identical. doc/references.bib parses 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__.py registration, 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's HarmEval 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:123 asks 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 (curl on 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 columns Question/Topic + split train + 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 a Topic string (which would land that row in OTHER rather than fail) or an off count.

Two unrelated things noticed

Not fixed here; happy to send separate PRs.

  1. doc/code/datasets/1_loading_datasets.ipynb is 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.
  2. .github/instructions/datasets.instructions.md names the helper _fetch_from_huggingface at 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.

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.
@romanlutz
Roman Lutz (romanlutz) added this pull request to the merge queue Sep 23, 2026
Merged via the queue into microsoft:main with commit 0003422 Sep 23, 2026
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FEAT Add support for the HarmEval dataset

2 participants