SKY-D224 · AI-code defects
API signature hallucination
An API signature hallucination is a call to a library function, method or keyword argument that the installed library does not have, such as requests.Session(timeout=10). SKY-D224 imports the library in the Python that runs Skylos, reads the real function signatures and compares each call in your code with them.
- 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). Counts toward
max_ai_defects. HIGH findings do not fail the gate on their own unlessblock_ai_defect_severitiesunder[tool.skylos.gate]lists"HIGH". The agent hook (skylos verify) blocks on it. - Finding type
- review
Why it matters
Coding agents mix up similar libraries and versions, so they write calls that look right and fail with TypeError or AttributeError the first time the line runs. A wrong keyword in a rarely used path, such as a retry or timeout setting, often ships because no test reaches it.
What Skylos flags
import requests API_URL = "https://api.example.com/v1/orders" def fetch_orders(token): session = requests.Session(timeout=10) session.headers["Authorization"] = f"Bearer {token}" response = session.get(API_URL) response.raise_for_status() return response.json()What Skylos leaves alone
import requests API_URL = "https://api.example.com/v1/orders" def fetch_orders(token): session = requests.Session() session.headers["Authorization"] = f"Bearer {token}" response = session.get(API_URL, timeout=10) response.raise_for_status() return response.json()Why Skylos leaves it alone
requests.Session() takes no arguments, but Session.get() passes extra keywords on to the request, so timeout=10 is accepted there. Skylos checks each keyword against the signature of the exact function called; a function that takes **kwargs accepts every keyword.
How Skylos decides
- Checks only imports of a short list of packages:
requests,pandas,boto3,openaiandjwtby default.api_signature_modulesunder[tool.skylos]replaces that list. A file that never mentions one of these names is skipped, and a package name the project uses for its own module, or a relative import, is never checked. - Imports each package in the Python environment that runs Skylos and records its public functions, classes, methods and their parameters. The result is cached in
.skylos/cache/and reused while the environment stays the same. A package that is not installed, or fails to import, is skipped and counted as unchecked in the scan summary. - Skips a package when the project declares a different distribution for the same import name, or a version on another major release line than the installed one (
PyJWT<2declared, 2.x installed): the installed API is then no evidence about the project's. - Follows
import requests,from requests import Session, aliases and objects created from a known class (session = requests.Session()). It reports a call to a module function or class the package does not expose, a method the class does not have, and a keyword argument the signature does not accept. Afrom pkg import nameof a missing name is reported where the name is called. Bare decorators from these packages are checked as calls. - Stays silent for imports inside
try/except ImportErrororcontextlib.suppress(ImportError), afrom pkg import namenested underifor a loop, functions that take**kwargs, and members or signatures the inspection could not read in full. An import of a submodule the package does not have (from requests.retry import Retry) is reported as SKY-L012.
How to fix it
Check the library's documentation for the version you install and move the argument to the call that accepts it, or use the function that exists. Pin the library in your manifest so Skylos, your tests and production agree on one API.
import requests API_URL = "https://api.example.com/v1/orders" def fetch_orders(token):Removed: session = requests.Session(timeout=10)Added: session = requests.Session() session.headers["Authorization"] = f"Bearer {token}"Removed: response = session.get(API_URL)Added: response = session.get(API_URL, timeout=10) response.raise_for_status() return response.json()When it can be wrong
- The check reads the package installed next to Skylos. If Skylos runs in its own environment (
pipx, a CI image) with another version than your project, and your manifest does not pin the version, a call that is valid in your version can be reported. Run Skylos in the project's environment, or declare the version so mismatched majors are skipped. - A method added at run time, for example by a plugin that patches the class, is not in the recorded signature and is reported.
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
On the reported line, with the reason the call is valid:
Python session = requests.Session(timeout=10) # skylos: ignore[SKY-D224] patched by our plugin[tool.skylos] ignore = ["SKY-D224"]turns the rule off for the project.