Repository navigation
FIX: Strip Raku module adverbs before the registry lookup in PackageHallucinationScorer - #3538
Open
Jaafer Rahmani (bIackr0se) wants to merge 1 commit into
Open
Jaafer Rahmani (bIackr0se) wants to merge 1 commit into
Jaafer Rahmani (bIackr0se) wants to merge 1 commit into
Conversation
…allucinationScorer
This branch has not been deployed
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
PackageHallucinationScorerwithPackageEcosystem.RAKUkept the first module adverb as part of the package name:use JSON::Fast:ver<0.19>;becameJSON::Fast:ver, which is in no registry, so a reply that uses a known module scoredTrue. This PR separates the module name from the adverbs attached to it and sends only the name to the registry lookup.Raku attaches adverbs such as
:ver,:authand:apito a module name to select a release, in any order (long module names, e.g.use Dog:auth<Somebody>:ver<2.0>;). The Raku pattern now captures the name and the adverb chain as two groups, reading<...>and(...)values bounded to one line. A reference whose:fromadverb names another language, such asuse DBI:from<Perl5>;(a Perl module loaded through Inline::Perl5), is skipped, because the Raku registry does not list those modules.:from<Raku>and:from<Perl6>still load Raku modules (CompUnit::Repository::FileSystem.candidates), so those stay checked. The last:fromdecides, as Rakudo keeps the later of two repeated adverbs (colonpairs_hash). The skip applies only when every adverb value is a plain literal; with an expression such as:from($lang), or a value with escapes or nested brackets, the module stays checked.Single replies through
score_async, fenced as Raku, with the registry the scenario loads (garak-llm/raku-20250811, 2138 names):Across 115 Raku files from GitHub code search that use these adverbs, each scored as an assistant reply with the same registry, 45 files change from
TruetoFalseand none fromFalsetoTrue. Everyuse,needorrequireline without an attached adverb extracts the same names before and after.A stub target returning
use JSON::Fast:ver<0.19>:auth<zef:timo>;plus one line of code, sent throughPromptSendingAttackwith this scorer as its objective scorer, givesSUCCESSon main ("Hallucinated raku packages: JSON::Fast:ver") andFAILUREwith this change.Tests and Documentation
tests/unit/score/test_package_hallucination_scorer.py::ver,:authand:apiin both orders,:ver<1.2+>,:ver('0.19'),need,require,:from<Raku>,:from<Perl6>,:from($language),:from("$language"),:from(LANG),:from<Perl5>text inside an:auth(...)or a nested or escaped:auth<...>value,:from<Perl5>followed by:from<Raku>, a leading::and a fenced line without a semicolon all giveJSON::Fast;:from<Perl5>and:from('Python')references are skipped whileFake::Module:ver<1>in the same reply is still reported;Foo::Bar-Baz,Don't::Panic,Foo::verandTest::Mock(fromuse Test::Mock :ALL;) keep their full names;False.pytest tests/unit/score tests/unit/scenario/garak: 5303 passed.pre-commit runon the changed files passes (ruff format, ruff check, ty).