Skip to content

FEAT: Adding Garak package hallucination scenario - #2141

Merged
Richard Lundeen (rlundeen2) merged 7 commits into
microsoft:mainfrom
rlundeen2:rlundeen2-garak-package-hallucination
Aug 14, 2026
Merged

FEAT: Adding Garak package hallucination scenario#2141
Richard Lundeen (rlundeen2) merged 7 commits into
microsoft:mainfrom
rlundeen2:rlundeen2-garak-package-hallucination

Conversation

@rlundeen2

Copy link
Copy Markdown
Contributor

Description

Ports garak's packagehallucination probe into PyRIT as a scenario plus a deterministic scorer, following the web_injection precedent.

  • PackageHallucinationScorer (under pyrit/score/true_false/regex/): extracts imported package names from model-generated code and flags any that are absent from an injected known-good reference set (Python stdlib added automatically). It lives beside the RegexScorer family but deliberately does not subclass it — its contract is extract-then-allow-list, the inverse of RegexScorer's match-means-hit — and the docstring explains why.
  • PackageHallucination scenario covering Python, JavaScript, Ruby, and Rust.
  • The prompt/task corpus lives in local .prompt datasets under seed_datasets/local/garak/ (auto-discovered) rather than being hardcoded in scenario code, keeping dataset ownership out of the scenario.

Tests and Documentation

  • Unit tests: tests/unit/score/test_package_hallucination_scorer.py and tests/unit/scenario/garak/test_package_hallucination.py.
  • Docs: added a PackageHallucinationScorer example to doc/code/scoring/1_true_false_scorers and the scenario to doc/scanner/garak.
  • Ran JupyText with execution on doc/code/scoring/1_true_false_scorers.py to regenerate the notebook.

Port garak's packagehallucination probe into PyRIT as a scenario plus a
deterministic scorer, following the web_injection precedent.

- Add PackageHallucinationScorer under score/true_false/regex/ (extract-then-
  allow-list; documented why it does not subclass RegexScorer).
- Add PackageHallucination scenario covering Python/JavaScript/Ruby/Rust.
- Move the prompt/task corpus into local .prompt datasets under
  seed_datasets/local/garak/ instead of hardcoding it in scenario code.
- Document the scorer in doc/code/scoring/1_true_false_scorers and the scenario
  in doc/scanner/garak.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Comment thread doc/code/scoring/1_true_false_scorers.ipynb
Comment thread doc/code/scoring/1_true_false_scorers.py
…ge-hallucination

Migrated the PackageHallucination scenario to main's ScenarioTechnique API
(ScenarioStrategy -> ScenarioTechnique, SeedAttackGroup -> AttackSeedGroup) and
resolved doc conflicts (added a Doctor section from main, regenerated the
true/false scorer notebook to include both the new PackageHallucinationScorer
subsection and main's new scorer sections).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 87fecfc8-b093-42a4-b36d-09e437ca1b2a
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 87fecfc8-b093-42a4-b36d-09e437ca1b2a
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 87fecfc8-b093-42a4-b36d-09e437ca1b2a
@rlundeen2
Richard Lundeen (rlundeen2) added this pull request to the merge queue Aug 14, 2026
Merged via the queue into microsoft:main with commit d1f7306 Aug 14, 2026
54 checks passed
@rlundeen2
Richard Lundeen (rlundeen2) deleted the rlundeen2-garak-package-hallucination branch August 14, 2026 00:32
Richard Lundeen (rlundeen2) added a commit to rlundeen2/PyRIT that referenced this pull request Aug 14, 2026
Preserve the package hallucination and system prompt extraction scenarios, scorers, datasets, exports, tests, and Garak documentation.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d5380728-0f8d-4cc2-b665-055180af481b
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.

2 participants