Repository navigation
FIX Ignore Perl version declarations in PackageHallucinationScorer - #3481
Merged
jbolor21 merged 2 commits intoOct 23, 2026
Merged
Conversation
The Perl pattern captured 5 from use 5.010; and v5 from use v5.36;, so a Perl answer that declared its required Perl version was flagged as referencing a hallucinated package. Version declarations are now dropped, as the Raku branch already does for use v6.d;. Fixes microsoft#3480 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jbolor21
approved these changes
Oct 23, 2026
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
Fixes #3480.
PackageHallucinationScorerwithPackageEcosystem.PERLmatchedusestatements with(?:{3}|^)use\s+([A-Za-z0-9_:]+)\b. That pattern stops at the dot, so the version declarations idiomatic Perl starts with,use 5.010;anduse v5.36;, were captured as5andv5. Neither is in any registry, so a correct Perl answer scoredTrueand thePackageHallucinationscenario'sperl` technique counted it as a successful attack.Changes:
_extract_package_referencesdrops Perl references that are only a version, matchingv?\d[\d_]*in full:5,5_010andv5. This is what the pattern captures fromuse 5;,use 5.010_001;,use 5.36.0;,use v5;anduse v5.36;.use v6.d;the same way.Module names are unaffected, including ones that contain digits such as
Digest::SHA1, and the other ecosystems are unchanged.Tests and Documentation
tests/unit/score/test_package_hallucination_scorer.py:use 5;,use 5.010;,use 5.010_001;,use 5.36.0;,use v5;,use v5.36;, and a declaration right after a code fence are not extracted.Digest::SHA1andFake::Module2are still extracted next to a version declaration.use 5.010;,use v5.36;and a known module scoresFalsewith no hallucinated packages.mainall 9 new tests fail (5orv5is extracted and the answer scoresTrue); with this change they pass.pytest tests/unit/score tests/unit/scenario: 6664 passed, 122 skipped.ruff check,ruff formatandty checkpass on the changed files.🤖 Generated with Claude Code