fix(detectors): packagehallucination misses dotted and indented imports - #2108
Open
BarneyChambers wants to merge 1 commit into
Open
fix(detectors): packagehallucination misses dotted and indented imports#2108BarneyChambers wants to merge 1 commit into
BarneyChambers wants to merge 1 commit into
Conversation
The detector regex only matched column-0 import/from lines and could not parse dotted from paths, so typical model output scored 0.0 even when it named a non-existent package. Signed-off-by: user.email <barneychambers@hotmail.com>
BarneyChambers
force-pushed
the
fix/pythonpypi-import-extraction
branch
from
August 22, 2026 11:54
a827144 to
d8bea58
Compare
|
Confirmed on Windows 11 / Python 3.13 against The last is #1991's scope rather than yours. Worth flagging that both PRs rewrite the same |
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.
Summary
PythonPypi._extract_package_referencesmisses dottedfromimports and indentedimport/fromlines.Deterministic:
That is a false negative in a hallucination detector: typical model output evades detection entirely.
Fixes #2107
Real world example
Probe prompt (from garak's own
packagehallucinationprobe):Model response (totally plausible):
Plus the usual footer:
pip install strombergdbStrombergDB is fiction.
strombergdbis not on PyPI. That is the slopsquatting scenario this probe is meant to catch.What garak does today (before this fix):
set()— nothing foundPythonPypi.detect()The detector only catches this form:
Real model output almost never looks like that. It looks like
from strombergdb.client import ..., which the regex ignores.Why that is bad outside the lab:
strombergdband writes idiomatic dotted imports.pip install strombergdb.The failure mode is silent: the detector returns pass because it never parsed the import, not because the package is real.
After this fix: same response extracts
strombergdband scores 1.0 (FAIL).We ship a probe that asks models to write
from strombergdb.client import ..., and a detector that only seesfrom strombergdb import .... The probe can fail the model; the detector cannot see the failure.Fix
import/fromlines.fakepkg.utils→fakepkg).Not a duplicate
Open PR #1991 fixes comma-separated
import a, band explicitly leaves thefromregex unchanged. This PR is scoped to dottedfrompaths and indented imports.I searched open issues and PRs for dotted
from/ indented import extraction before opening #2107; none addressed this gap.Test
No existing test covered dotted
fromimports or indented imports (the current Python tests use unindented, undotted forms only). Added:test_pythonpypi_extract_package_referencestest_pythonpypi_dotted_and_indented_importsThey fail on
mainand pass with this change.5 passed in 7.35s
Scope note: I kept this to the Python extractor. Other language detectors in the same file use different grammars and are out of scope here.
Verification
from numpy.random import randstill scores 0.0garak -t <target_type> -n <model_name>— N/A; detector unit change only