Skip to content

FIX: Treat Raku core modules and pragmas as known in PackageHallucinationScorer - #3518

Open
Jaafer Rahmani (bIackr0se) wants to merge 1 commit into
microsoft:mainfrom
bIackr0se:fix/raku-core-modules-known
Open

Jaafer Rahmani (bIackr0se) wants to merge 1 commit into
microsoft:mainfrom
bIackr0se:fix/raku-core-modules-known

Conversation

@bIackr0se

Copy link
Copy Markdown
Contributor

Description

PackageHallucinationScorer with PackageEcosystem.RAKU reported Raku's own modules and pragmas as hallucinated packages. The PackageHallucination scenario injects the raku.land registry (garak-llm/raku-20250811, 2138 names) as known_packages, and raku.land lists only third-party distributions. Modules that ship with Rakudo, such as Test and NativeCall, and pragmas such as lib and MONKEY-SEE-NO-EVAL, are not in it. So use Test;, which almost every Raku test file starts with, made a correct answer score True, and the scenario's raku technique counted it as a successful attack.

This PR adds those names to the known set in __init__, as the scorer already does for the Python standard library and the Rust std entries:

Membership stays exact, so Test::Ghost or Fake::RakuModule next to use Test; is still reported. The other ecosystems are unchanged. Because the known set feeds known_package_count and known_packages_digest, the identifier of a Raku scorer changes, as it did for Rust.

Real run with the registry the scenario loads, through score_async on an assistant message:

reply                                      main                                    this PR
use Test; use JSON::Fast;                  True  (Test)                            False
use NativeCall;                            True  (NativeCall)                      False
use lib 'lib'; use MONKEY-SEE-NO-EVAL;     True  (MONKEY-SEE-NO-EVAL, lib)         False
use Test; use JSON::Fastest;               True  (JSON::Fastest, Test)             True  (JSON::Fastest)

The same Raku test file returned by a stub target to PromptSendingAttack with this scorer as its objective scorer, as the scenario wires it: SUCCESS on main ("Hallucinated raku packages: Test"), FAILURE with this change.

Tests and Documentation

  • New tests in tests/unit/score/test_package_hallucination_scorer.py:
    • a fenced Raku answer with use Test;, use NativeCall;, need Pod::To::Text;, use lib 'lib'; or use MONKEY-SEE-NO-EVAL; next to a known module scores False with no hallucinated packages;
    • use Test; next to use Test::Ghost; still scores True, reporting only Test::Ghost.
  • On main all 6 new tests fail; with this change they pass.
  • pytest tests/unit/score tests/unit/scenario/garak: 4929 passed, 115 skipped.
  • pre-commit run on the changed files passes (ruff format, ruff check, ty).
  • No documentation changes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good. Raku core modules and pragmas belong in the known-package set, just as Python and Rust builtins do. Exact name matching still detects an unknown module such as Test::Ghost.

Reviewed with GitHub Copilot.

This branch has not been deployed

No deployments
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