Skip to content

[FEAT] Add SemGuard Arabic Security Dataset loader - #2468

Merged
hannahwestra25 merged 12 commits into
microsoft:mainfrom
AbdaullahAG:main
Sep 22, 2026
Merged

hannahwestra25 merged 12 commits into
microsoft:mainfrom
AbdaullahAG:main

Conversation

@AbdaullahAG

Copy link
Copy Markdown

Description

Adds a SeedDataset loader for the SemGuard Arabic Security
Dataset — 807 validated Arabic/Arabizi/English prompt attack
examples across 7 threat categories (injection/jailbreak,
phishing, privacy leakage, violent incitement, harmful content,
impersonation, safe). Validated via a three-judge LLM-as-Judge
pipeline (GPT-4o, Grok-4, Llama 3.3 70B; Fleiss' kappa = 0.839).

Closes #2331.

Implementation notes, per the discussion in #2331:

  • Category enum: SemGuardCategory (7 values) lets callers
    filter by threat category, following the VLGuardSubset pattern.
    SAFE is included as an explicit filterable value rather than
    always loaded, per Roman Lutz (@romanlutz)'s point about excluding safe
    prompts by default.
  • Language accessibility: each seed's metadata includes a
    language field (ar, en, or code-switched), so users can
    filter or at least identify non-English prompts programmatically
    even without reading Arabic. Category-level docstrings and the
    loader's own docstring describe each category in English. Open
    to adding English glosses per-seed if that would help further.
  • harm_categories mapping: PyRIT's HarmCategory taxonomy
    doesn't have a direct entry for "prompt injection" as an attack
    technique (as opposed to a content-harm type), so
    injection_jailbreak maps to COORDINATION_HARM via
    HARM_CATEGORY_ALIAS_OVERRIDES. Flagging this in case a more
    precise mapping is preferred.
  • The dataset itself is CC BY 4.0 licensed (separate from this
    loader file's MIT license, consistent with how gated/externally
    licensed datasets like VLGuard are handled).

Paper: accepted at IEEE AEECT 2026 (citation added to
references.bib / bibliography.md).

Tests and Documentation

  • Added tests/unit/datasets/test_semguard_dataset.py: 9 tests
    covering happy-path fetch, category filtering, empty-after-filter
    raises ValueError, empty-text rows are skipped, dataset_name
    property, HARM_CATEGORY_ALIAS_OVERRIDES coverage for all 7
    categories, and SemGuardCategory enum values. All passing
    locally (pytest tests/unit/datasets/test_semguard_dataset.py -v
    → 9 passed).
  • Registered the loader and SemGuardCategory in
    pyrit/datasets/seed_datasets/remote/__init__.py.
  • Added BibTeX entry (abughallous2026semguard) to
    doc/references.bib and the cite key to doc/bibliography.md.
  • Updated doc/code/datasets/1_loading_datasets.py (prose list)
    and regenerated the notebook via:
    jupytext --to ipynb --execute doc/code/datasets/1_loading_datasets.py
    — ran clean, confirmed semguard appears in the executed
    get_all_dataset_names_async() output cell alongside the other
    built-in datasets.

…Dataset loader for the SemGuard Arabic Security Dataset:807 validated Arabic/Arabizi/English prompt attack examples across7 threat categories, validated via a three-judge LLM-as-Judgepipeline (GPT-4o, Grok-4, Llama 3.3 70B; Fleiss' kappa = 0.839).Introduces SemGuardCategory enum for filtering by threat category.
…y-path fetch, category filtering, empty-after-filterraises, empty-text-skipped, dataset_name property, harm categoryalias overrides, and SemGuardCategory enum values.
@AbdaullahAG

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@AbdaullahAG

Copy link
Copy Markdown
Author

Hi Roman Lutz (Roman Lutz (@romanlutz)) — just following up on #2468 whenever you get a chance. It's ready for review (9 unit tests passing, notebook regenerated), though I noticed the CI checks are still pending maintainer approval to run, so let me know if there's anything needed on my end to move that along.

@hannahwestra25 hannahwestra25 self-assigned this Sep 2, 2026
… enum values via _validate_enums, let original exceptions propagate

- SAFE is now opt-in via categories=[SemGuardCategory.SAFE], not
  loaded by default (default set is the six attack categories)
- categories validated via self._validate_enums for immediate
  ValueError on invalid input
- Removed generic Exception wrapper; ValueError, auth failures,
  and fetch errors now propagate with their original type
- Added tests: safe excluded by default, safe included when
  requested, invalid category raises, propagated ValueError type
- Regenerated notebook per review comment
@AbdaullahAG

Copy link
Copy Markdown
Author

hannahwestra25 Thanks for the thorough review , addressed all four points:

  1. SAFE excluded by default: default category set is now the six attack categories. SemGuardCategory.SAFE must be requested explicitly (e.g. categories=[SemGuardCategory.SAFE]) for control/over-refusal evaluation. Added tests covering both the default-exclusion path and explicit-inclusion path.

  2. Validation via _validate_enums: category values are now validated immediately at init time using the base loader's _validate_enums, so invalid input raises ValueError before any fetch happens. Added a test for the invalid-category case.

  3. Exceptions propagate unwrapped: removed the generic Exception wrapper — ValueError (empty result) and any fetch-layer errors (auth, network, schema) now propagate with their original type. Updated the empty-result tests to assert ValueError specifically.

  4. Notebook regenerated via the exact command specified.

All 12 unit tests passing locally (pytest tests/unit/datasets/test_semguard_dataset.py -v).

…lass-level harm_categories

- text/category now use (item.get(k) or '').strip() since HF's CSV
  loader returns None for blank cells, not missing keys
- injection_jailbreak now maps to HarmCategory.DECEPTION instead of
  COORDINATION_HARM (deceptive-inducement framing fits prompt
  injection better than coordination-of-harm)
- Added class-level harm_categories = [c.value for c in SemGuardCategory],
  following the CoCoNot pattern, so dataset-level metadata isn't blank
- Added test_fetch_dataset_skips_item_with_none_text and
  test_class_level_harm_categories_metadata
…ip-notebook-progress-bars, EOF, ruff-format)
@AbdaullahAG

Copy link
Copy Markdown
Author

hannahwestra25 Addressed all four points from your review:

  • Null-safe parsing: text/category now use (item.get(k) or "").strip() instead of .get(k, default), since HF's CSV loader returns None for blank cells rather than omitting the key. Added test_fetch_dataset_skips_item_with_none_text covering this case.
  • Harm category mapping: injection_jailbreak now maps to HarmCategory.DECEPTION instead of COORDINATION_HARM deceptive inducement fits prompt injection/jailbreak better than coordination-of-harm.
  • Class-level harm_categories: Added harm_categories: list[str] = [c.value for c in SemGuardCategory] following the CoCoNot pattern, with test_class_level_harm_categories_metadata covering it.
  • Notebook: Ran pre-commit run --all-files locally, which caught and fixed the leftover local paths/tqdm output plus a few unrelated formatting nits (ruff-format, end-of-file-fixer).

All 14 unit tests passing locally. One unrelated note: the build-book version-matrix jobs (Build 0.12.1–1.1.0) are failing on git fetch ... releases/vX.Y.Z, which looks like a fork-specific issue (those release tags/branches don't exist on my fork) rather than anything in this PR flagging in case it's expected.

Also noticed the latest build_and_test run is showing "Action required" , could you approve it whenever you get a chance?

@hannahwestra25 hannahwestra25 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good! thanks so much for contributing!!

@hannahwestra25
hannahwestra25 added this pull request to the merge queue Sep 22, 2026
Merged via the queue into microsoft:main with commit a0cb2fa Sep 22, 2026
1 check 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.

Proposal: Arabic & Multilingual Security Contributions to PyRIT

2 participants