Skip to main content

SKY-D223 · Supply chain and agent configuration

Undeclared third-party import

Medium

A Python file imports a third-party package that the project's manifest (pyproject.toml, requirements.txt, setup.cfg or setup.py) does not declare. SKY-D223 reports the import line and names the distribution that would provide it.

Languages
Python
Turned on by
skylos . --ai-defects (or -a); reads the code as it is, no diff needed
Quality gate
counted toward the gate limits (full and diff scans). Reported with the AI-code findings and counted toward max_ai_defects. A MEDIUM finding does not fail the gate on its own unless block_ai_defect_severities under [tool.skylos.gate] lists "MEDIUM".
Finding type
review
Catalog name
Undeclared third-party dependency
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

The code works on the machine where the package happens to be installed and fails with ModuleNotFoundError in a clean install, a container or CI. Coding agents often add an import without touching the manifest, and the gap shows up only after release.

What Skylos flags

app/config.py · PythonReported on line 4
from pathlib import Path import requestsimport yaml  def load_settings(path: Path) -> dict:    with path.open() as handle:        return yaml.safe_load(handle)  def fetch_rates(url: str) -> dict:    return requests.get(url, timeout=10).json()
pyproject.toml · TOML
[project]name = "invoice-service"version = "1.0.0"dependencies = ["requests==2.32.3"]

What Skylos leaves alone

app/config.py: same as in the flagged example.

pyproject.toml · TOML
[project]name = "invoice-service"version = "1.0.0"dependencies = ["requests==2.32.3", "PyYAML==6.0.2"]

Why Skylos leaves it alone

The import is yaml but the distribution is called PyYAML. Skylos maps import names to the distributions that provide them, so a package declared under its distribution name counts.

How Skylos decides

  1. Runs with --ai-defects on Python files. For each file it finds the nearest manifest and reads the declared dependencies; nothing is installed or imported from the scanned project.
  2. Skips the standard library, the project's own modules and packages, names starting with _, imports in setup.py of build tools such as setuptools, and names listed in the SKYLOS_PRIVATE_DEPS_ALLOW environment variable.
  3. Looks the import up in the distributions installed next to Skylos. If one of them provides it and none of those is declared, it reports "Undeclared import 'yaml' (provided by: pyyaml)".
  4. Otherwise it uses a built-in map of import names to distributions, and then asks PyPI whether a project of that name exists. A package that exists and is not declared is reported here; a name that no PyPI project has is reported as SKY-D222 instead.
  5. Does not report when the project has no manifest at all, when a declared dependency or a lockfile edge provides the import, or when the import is used only under if TYPE_CHECKING:.

How to fix it

Declare the package, with the version you tested, in the manifest the project installs from. If the import was a mistake, remove it.

pyproject.toml · TOML · the fix, against the flagged file
[project]name = "invoice-service"version = "1.0.0"Removed: dependencies = ["requests==2.32.3"]Added: dependencies = ["requests==2.32.3", "PyYAML==6.0.2"]

When it can be wrong

  • The installed-package lookup uses the Python that runs Skylos. A package installed there under a different distribution name than the one you declared can be reported as undeclared.
  • A private package that is installed by other means, such as a base image, is reported. List it in SKYLOS_PRIVATE_DEPS_ALLOW (comma-separated names) for the scan.
  • An import that Skylos cannot match to any distribution, for example a module whose PyPI project has a different name, is still reported, with "(possible import/dist name mismatch)" in the message.

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • Mark a reviewed import on its own line.

    Python
    import yaml  # skylos: ignore[SKY-D223] installed by the base image
  • Accept existing findings with skylos baseline ., then scan with --baseline.

  • ignore = ["SKY-D223"] under [tool.skylos] turns the rule off for the whole project.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.