Scanning AI coding assistants with garak for hallucinated packages
Developers often accept an install command or an import line from a coding assistant without checking that the package exists. If the model invents a package name, anyone can register that name on a public registry with malicious code, and the next developer who follows the suggestion installs it. garak's package hallucination probes test this directly by trying to get code generations that specify non-existent and therefore insecure packages. Run this scan before a coding assistant is approved for a team, and again after any change to the underlying model, system prompt or retrieval setup, because each of these can change which names the model invents.
The probes cover Python, Ruby, JavaScript, Rust, Raku, Perl and Dart. On the detector side, garak checks generated package names against lists for PyPI, RubyGems, npm, crates and other registries. Those lists have to be current relative to the model being tested, so a name that was unregistered when the list was built may be claimed since then, and a stale list can make a result look better or worse than it is. Before trusting a result, confirm which registries your developers actually install from, whether your organization uses an internal mirror or allow list, and which language ecosystems your assistant is used for. Packages that exist only on an internal index are not in the public lists and will be flagged or missed depending on how you configure the scan.
This scan covers package names only. Malware in generated code and exploit generation are separate concerns that the package hallucination probes do not measure, so confirm which garak probes address them for your assistant before treating the scan as complete. For the assistant itself, treat each flagged name as a finding to triage: check whether the package exists, whether it was registered after the model's training data was collected, and whether your build pipeline would fetch it automatically. Ask your security team to decide in advance who reviews the findings, and how often the scan is rerun.
Which ecosystems the package hallucination probes cover
The Python probes ask the model to write code that imports packages, then the detector checks each suggested name against a list of packages published to PyPI. A name that does not appear on that list is a candidate for hallucination, and an attacker who registers that name can get malicious code installed by a developer who trusts the assistant. Python is often the first ecosystem teams test because data science, automation and backend code frequently rely on generated imports.
- Registry checked: the detector compares generated names against a PyPI package list, so the list date matters.
- Typical exposure:
pip installlines andimportstatements copied from assistant output into notebooks and scripts. - Shadowing risk: a hallucinated name can look like a real library, so typosquat-style names deserve review.
- Lists age: a package list that is older than the model may miss names that now exist, or include names that were later removed.
- Scope note: a clean result covers only the names the probe prompts elicited, not every import the assistant could produce.
Before relying on this tab, confirm in the garak source which Python probe and detector versions your release includes and how the PyPI list is refreshed.
The JavaScript probes target code that pulls in npm packages, and the detector checks suggested names against an npm registry list. Front-end and Node.js assistants often produce require or import statements and npm install commands for libraries that do not exist, which is exactly the gap a public squatter can fill. Because npm packages install with build and lifecycle scripts, a single bad name can run code on a developer workstation or a CI runner.
- Registry checked: npm names are compared against an npm package list maintained for the detector.
- Typical exposure: generated
package.jsonentries,npm installcommands and bundler configuration. - Install-time execution: lifecycle scripts make a hallucinated dependency a code execution risk, not only a supply chain nuisance.
- Scoped and unscoped names: check how the detector treats scoped packages before you read the result as complete.
- Front-end overlap: the same assistant may serve both browser and server code, so run both contexts.
Confirm the current npm coverage in the garak source and decide whether your pipelines block unknown dependencies before anyone reviews them.
The Rust probes ask for code that adds crates as dependencies, and the detector checks names against the crates registry. Rust projects are compiled and often pulled into security-sensitive tooling, so a fabricated crate name in Cargo.toml or a cargo add command deserves the same scrutiny as a Python or npm name. Developers who trust compiler success may not notice that a dependency was never a real project.
- Registry checked: generated crate names are compared against a crates list used by the detector.
- Typical exposure:
Cargo.tomldependency tables,cargo addcommands andusestatements. - Build-time risk: build scripts in a crate can run during compilation, so an unvetted name reaches the build host.
- Native code: crates that wrap system libraries may need extra review even when the name is real.
- Lockfile discipline: a committed
Cargo.lockhelps show what was actually resolved.
Confirm whether the crates list in your garak version is current, and review how generated dependencies are checked against your approved sources.
The garak source includes package hallucination probes for Ruby, Raku, Perl and Dart, and the detectors check names against registries such as RubyGems for Ruby. These ecosystems are usually smaller in a given organization, so teams often assume they are covered by the larger ones. Check each one separately, because the probe prompts, list sources and update cadence can differ from the Python and JavaScript coverage.
- Registry checked: Ruby names map to RubyGems, and the other registries are listed in the garak detector source.
- Typical exposure:
Gemfileentries,gem installcommands and Perl or Raku module declarations. - Legacy codebases: older Ruby, Perl and Raku systems often generate code assistants have seen less of, which affects output quality.
- Dart and Flutter: Dart package names appear in
pubspec.yamland need their own check. - Gaps: if a language in your estate has no probe, record that as a known gap rather than a pass.
Verify the Ruby, Perl, Raku and Dart probe and detector entries in the garak source for your release, and document which of these languages your assistant produces code for.
Some teams depend on registries or internal package indexes that the public probes do not cover. A hallucinated name that matches a private package is safe only if the internal index is trusted, while a name missing from both public and private sources is the risky case. This tab helps you decide what to add beyond the default coverage, such as a custom detector or a manual review step.
- Private indexes: names that exist only in your internal registry may be flagged even though they are safe to use.
- Allowlists: maintain an approved package list per language so the review step has a reference.
- Custom detectors: garak's plugin model can extend detectors, which you should test before trusting.
- Registry changes: packages get removed, renamed or transferred, so a list check is a point-in-time signal.
- Ownership: assign someone to review new flags for each ecosystem your team uses.
Agree with your security and platform teams which registries and internal indexes count as trusted, and confirm how garak handles each one in the version you deploy.
How garak decides a package name is hallucinated
garak's package hallucination probes send a coding prompt to the model under test, such as a request for a script that imports a library for a specific task. The generated code then passes to the package hallucination detectors, which extract the package names the code tries to install or import and check each name against a list for its registry, such as PyPI for Python, npm for JavaScript, crates for Rust or RubyGems for Ruby. A name that is absent from the list is flagged, and the probe records a FAIL when a flagged name appears in the output. Because the probes use the default setting of 5 generations per prompt, the same model can produce a hallucinated name in some attempts and a real one in others, so the failure rate matters as much as any single result.
The detector's verdict is only as good as the registry list it checks against. Those lists must be current relative to the model: a package published last month will look hallucinated if the list was built before it existed, which is a false positive. The opposite error, a false negative, happens when a name is squatted or was created after the list was built and the detector accepts it because it now appears in the list. Before you trust a scan, confirm with the garak maintainers or the source code how each registry list was built and how often it refreshes, then record the list date alongside the scan results so a later reviewer can judge the verdict.
Treat every FAIL as a lead, not a finding. Open the generated code and check the flagged package on its registry directly: whether it exists, when it was published, who maintains it and whether its contents match what the model's code expects. A name that is absent today may still be the target of an attacker who registers it after the scan, so the risk lies in the code the assistant would produce for your developers. Record the prompt, the output and your review decision in the scan report, and route confirmed cases to the team that controls dependency policy, such as an allowlist or a private registry mirror, before anyone changes the assistant's configuration.
How a package hallucination scan flows from prompt to finding
The scan starts in garak, which sends probe prompts through a generator to the coding assistant endpoint, so the trust boundary sits between the scanner and the assistant. The generated code returns to the package hallucination detector, which checks each named package against the registry list for its ecosystem, such as PyPI or npm. Each attempt lands in the JSONL report, and a failed probe becomes a finding for review. Check that the registry lists are current for the model under test, because a stale list can mark real packages as missing.
Probe prompts cross the trust boundary, and detector results feed the report.
Scan options and when each fits a coding assistant
This table compares generator, generation count and probe selection choices for a coding assistant scan. Read each row as a trade-off between coverage, runtime and API cost, and confirm the endpoint details listed in the last column before you commit to a configuration. The main takeaway is that the packagehallucination probes alone give a focused first pass, while broader families add coverage at higher runtime and cost.
| Option | What it covers | Runtime and cost trade-off | What to confirm first |
|---|---|---|---|
| REST generator for an in-house assistant | Tests the assistant as users reach it, including its system prompt, retrieval and any code-review layer in front of the model | Runtime depends on your endpoint's latency and rate limits, and you may pay for internal compute rather than per-token API fees | Whether the endpoint returns plaintext or JSON, how the response is shaped, and whether it accepts a session or API key |
| Hosted API generator (OpenAI, Bedrock, Replicate, Hugging Face Hub) | Tests the base model behind the assistant, which may differ from the product you ship | Each generation is billed by the provider, so cost grows with probe count and generations per prompt | Model version pinned in the config, provider rate limits, data handling terms, and whether the model matches what developers actually use |
| Local model through llama.cpp or LiteLLM | Tests a self-hosted model or a gateway that routes to several models under one interface | No per-call API fee, but runtime depends on local hardware and quantization, and long scans can tie up a GPU or CPU host | Model file or gateway route name, hardware capacity, and whether the quantized build behaves like the production model |
| Default count of 5 generations per prompt | Catches intermittent hallucinated package names, since a single failed attempt marks the probe as FAIL | Highest runtime and API cost of the options in this table, because every prompt runs five times | Whether your budget and time window allow a full run, and whether the endpoint enforces rate limits that slow five-attempt runs |
| Fewer generations per prompt for cost control | Gives a faster read on whether the assistant hallucinates packages at all, but may miss rare outputs | Lower cost and shorter runs, with a higher chance that a weak result is a false negative | Use a reduced count for smoke tests, then rerun at the default count before you draw a release decision |
| packagehallucination probes alone | Focuses on non-existent package names across Python, Ruby, JavaScript, Rust, Raku, Perl and Dart | Smallest run and lowest API spend, suited to repeated checks in a pipeline | Whether your stack uses ecosystems outside the probe list, and whether the detector registry lists are current for the model's training period |
| packagehallucination plus other families | Adds malware, exploit and prompt injection coverage that shapes what an assistant will write or run | Longer runtime and higher API cost, because each added family multiplies the prompts sent to the endpoint | Which families match your threat model, and whether the assistant executes generated code or only displays it |
| Scheduled rescans after model or prompt changes | Shows whether a new model version or system prompt changed package hallucination rates | Recurring cost on every run, so keep the probe set stable to make results comparable | Whether the endpoint version is recorded with each report, so runs can be compared over time |
Setting up a garak package hallucination scan
This sequence takes a team from an empty host to a scored package hallucination run against a coding assistant, with a report that shows which languages were probed and what the model proposed. Each step ends with a check so problems surface before the results are read.
Confirm the Python version and install garak
On a Linux or macOS host, confirm that Python 3.11 or newer is available, then create a virtual environment and install garak from PyPI with pip. garak is a command-line tool, so the install is done on the machine that will run the scan, which can be a host inside your network. Check the install by running the garak help command and confirming that it prints the option list without errors. Record the installed version so the report can be tied to it later, because scores can shift between releases.
Describe the coding assistant endpoint
If the assistant is a hosted model with a built-in garak generator, such as OpenAI or Hugging Face, select that generator by name and supply the credentials through environment variables. If the assistant sits behind your own API, write a short YAML file for the REST generator that gives the endpoint URL, the request body template, the header that carries the key, and the path to the response text. Use a test key with the least privileges that still return code. Check the configuration by sending one short prompt through the generator and confirming that the response is code, not an error page, a refusal or a login redirect.
Select the package hallucination probes
List the available probes and choose the packagehallucination probes for the languages your developers use. garak provides probes for Python, Ruby, JavaScript, Rust, Raku, Perl and Dart. Include only the languages your teams actually ship, because each extra probe adds generations and run time. Confirm the selection with the list command, which shows the probes that will run before any prompts are sent. Note the registry each language maps to, since the detectors compare names against registry lists.
Run the scan with the probe selection
Start the scan with the chosen generator and the probe selection, keeping the default of five generations per prompt unless you have a documented reason to change it. Run the scan from a tracked script or configuration file so it can be repeated against the same assistant later. Watch the console output for each probe name to confirm that every intended language started, and that no probe was skipped because of a configuration error. Wait for the run to finish before reading any results.
Check that the probes ran for each language
Open the JSONL report written by the run and confirm that there is an entry for every language you selected. Count attempts per probe and check that the number matches the generations you configured. Look at a few raw outputs to confirm that the assistant returned code with import or install statements, which is what the detectors need to evaluate. If a language has no attempts or every output is prose, fix the generator or prompt setup before drawing any conclusion about that language.
Review the detector output and package names
For each probe marked as FAIL, read the package names the detector flagged as nonexistent in the relevant registry. Confirm each flagged name yourself by checking the registry directly, because a detector result depends on the registry list it was given being current for the model. Record which names are not on the registry, which ones have been registered by someone else, and which are simply misspellings. This review produces the list you will use to decide what to block, pin or warn about.
Review garak.log and keep the run record
Open garak.log and check for errors, timeouts or retries that could have changed which prompts reached the assistant. Note that the log continues across runs, so filter it by the run timestamp. Store the JSONL report, the log extract, the configuration file and the garak version together under a dated folder. The run is complete when a second person can rerun the same configuration and find the same probe and language coverage in the report.
Security risks when a scan touches live package registries and secrets
A garak scan against a coding assistant sends prompts to a live endpoint, may check generated names against public registries, and writes reports full of model output. Each of the risks below comes from one of those touchpoints, so each needs its own control before the first run.
Keep API keys out of config files
The generator configuration for a hosted coding model usually holds an API key or token. Store it in an environment variable or your secrets manager and reference it from the generator config rather than pasting it into a YAML file that gets committed or copied between hosts. Confirm that garak.log and the JSONL report do not echo request headers or credentials, and check this on a test run before you scan a production endpoint. Rotate any key that appears in a shared file.
garak user guideReview every surfaced package name
A package hallucination finding means the model suggested a name that may not exist on PyPI, npm, crates or another registry. Before anyone runs pip install, npm install or cargo add on that name, check the registry directly, confirm the publisher, and read the package metadata. An unclaimed name is a squatting risk, not a dependency. Treat the scan output as a list of names to investigate, never as an install list, and block automated installs from scan results.
Limit registry lookups to read access
Checking whether a name exists on a registry needs only anonymous or read-only access. Do not give the scanning host publish tokens, organization credentials or write access to any package index. If your process verifies names against internal mirrors or private registries, scope the credentials to read-only and to the namespaces that scan needs. Confirm which registry hosts the scan machine can reach, and record them in the scan runbook.
Protect report files as sensitive data
The JSONL report records every prompt and generation, and generated code can contain internal function names, paths, or fragments of your own codebase if the scan used context. Store reports in an access-controlled location, limit who can read the garak.log file, and set a retention rule that matches your data policy. Decide before the first scan who may view findings, because the file is evidence of what the model produced.
Run scans from an isolated host
Run garak from a dedicated host or container that has network access only to the target coding endpoint and the registries you chose to check. Keep it out of the build network and away from developer workstations holding SSH keys or cloud credentials. Use a fresh virtual environment with Python 3.11 or newer, installed from PyPI, so that the scanner's own dependencies cannot reach your internal systems. Snapshot the host so a finding can be reproduced later.
Name an owner for each scan
Scans touching live registries and secrets need a named person who approves the target endpoint, the registries queried, the credential scope and the reviewer for package findings. Without that owner, reports pile up and nobody decides when a name is safe to ignore or to report to the registry. Write the approval into the scan plan, and record who reviewed each finding and what action followed.
Questions teams ask before scanning a coding assistant
Can our own team run garak against our coding assistant?
Yes, if your team can reach the model or assistant endpoint and has someone who can read Python-based tooling. garak is a command-line tool installed from PyPI with pip, and the PyPI package requires Python 3.11 or newer. The harder part is usually not installation but deciding which package hallucination probes match your languages, choosing how to call your assistant's endpoint, and judging which hits are real risks. Your team can do all three, but it needs time for each and someone accountable for the findings.
What makes a coding assistant scan take more effort?
Effort rises with the number of ecosystems, the way the assistant is reached, and how many findings need review. garak ships package hallucination probes for Python, Ruby, JavaScript, Rust, Raku, Perl and Dart, so each ecosystem you rely on adds probes to configure and results to read. Integration effort depends on whether the assistant exposes a model API or a product interface that needs a REST generator configured in YAML. Review effort depends on how many attempts fail and whether each one needs a developer to confirm the package is unsafe.
How long does a first garak scan of a coding assistant take?
The duration depends on your setup, and no fixed figure applies to every team. The main variables are how many ecosystems you test, whether the endpoint is ready for automated calls, how quickly you can get a test account, and how long the review of findings takes. garak makes 5 generations per prompt by default, so the number of attempts grows with the probe set and the number of generations you keep. Ask any partner to state the duration in the written scope, with the assumptions behind it.
What do we need to provide before a scan starts?
You need endpoint access, a test account with the same permissions a developer would have, and a named owner for each finding. Endpoint access means a reachable URL or model API key for the assistant under test, plus the request format if it is a custom service. The test account should reflect real developer permissions so results match production behavior. Owners should be developers or platform leads who can decide whether a suggested package is blocked, replaced or verified in your private registry.
What happens to a suggested package name that does not exist?
A package name that does not exist is a risk because an attacker can register it and wait for a developer or agent to install it. garak's detectors check generated package names against registry lists for PyPI, RubyGems, npm, crates and other registries, so the result depends on those lists being current for the model you test. Confirm with your team which registries your developers use, and make sure the findings report separates names that are missing from public registries from names that exist but are unsafe for other reasons.
Should we hire a partner to scan our coding assistant?
A partner is worth considering when you need coverage across many ecosystems, a fixed deliverable for an audit or procurement review, or a retest after fixes. DeployOpen runs fixed-scope engagements, with scope, deliverables and timelines agreed in writing before work starts. Ask any provider for the list of ecosystems and probes in scope, the endpoints and accounts they will use, who reviews findings, what the report contains, whether a retest is included, and what recurring support costs after the first scan.
Does a clean garak result mean our coding assistant is safe?
No, a clean result only means the probes you ran did not produce the undesirable output they test for. garak is a free tool that probes for weaknesses using static, dynamic and adaptive probes, and its results reflect the probe set, generations and detectors you selected. Package hallucination results also depend on registry lists that change over time. Treat a clean run as one input to your review, rerun after model or assistant updates, and record the configuration so the next run can be compared.
What to do with findings and how to retest
Treat a package hallucination finding as a supply chain risk that needs fixes in two places: the assistant and the way developers and pipelines consume its output. At the assistant layer, the first control is the system prompt, which can instruct the model to use only packages from an approved list and to flag any dependency it is unsure about. A stronger control is a package allowlist enforced outside the model, so an unlisted name fails review even when the model is confident. Where the assistant is connected to a registry lookup tool, confirm that the lookup runs before a package is recommended. At the process layer, the most important fix is dependency verification in CI: lock files must be generated from reviewed entries, new packages must be checked against the registry and its publication history before merge, and builds should fail on names that do not resolve to a known owner. Add a developer guideline that says an assistant's suggested install command is a proposal, not an approved change.
Retest with the same probes after every change that could move the result: a model version, a system prompt, an allowlist, or the registry list the detectors rely on. The detectors check generated names against lists for registries such as PyPI, RubyGems, npm and crates, and those lists must be current relative to the model under test, so refresh them before a rerun. Keep the JSONL reports from each run, and compare the same probe families, generation counts and configuration side by side. Confirm which garak version produced each report, because scores can shift after an upgrade for reasons unrelated to your controls. Before you credit a fix, check whether the change moved the score or only the sample. Finally, run the scan on a schedule, and record which findings were closed by a control and which were accepted, with an owner and a review date.
How DeployOpen scopes and delivers coding assistant scans
DeployOpen approaches coding assistant scanning as a fixed-scope engagement: the models, endpoints and package ecosystems are agreed in writing before any run starts. We configure garak in your environment, review the package hallucination results with your engineers, and leave you with a repeatable scan you can run again.
How we scope
- Agree which coding models, assistants and endpoints the written scope covers before testing starts
- Confirm which package ecosystems matter to your teams, such as Python, JavaScript, Rust or Ruby
- Record which registries your developers install from and how current your package lists are
- Set the number of generations per prompt and the probes to run, documented in the scope
How we build
- Install garak in your infrastructure and configure the generator for each coding assistant endpoint
- Select the package hallucination probes and detectors that match the ecosystems in scope
- Run the scans against the agreed configuration and keep the JSONL reports and garak.log output
- Review flagged package names with your engineers to separate true hallucinations from valid packages
How we hand over
- Deliver a findings report that lists hallucinated package names, the prompts that produced them and affected ecosystems
- Document the configuration files, commands and detector list so your team can rerun the scan
- Provide guidance on package allowlists, registry checks and developer workflow controls where findings warrant them
- Walk your security and platform engineers through the results and the retest plan
How we support
- Retest after fixes are applied and record how the results changed between runs
- Rerun scans after model or assistant upgrades, since package lists must stay current with the model
- Offer ongoing support, upgrades and continuous testing as a retainer if your scanning needs continue
- Confirm the support terms and retest scope in writing before work begins

