Fix the dependency screen for AI-suggested packages
Your task
You asked an AI for an HTML sanitizer, and it told you to pip install htmlsanitizer-pro. Models invent plausible package names, and attackers register those names to catch the installs. Your team now screens every AI-suggested dependency against the package index before anyone installs it.
An assistant wrote screen_dependency_suggestions(records, registry_names). It is in the editor. It has a bug. Find it and fix it.
Input and output:
records: one per suggested package, writtenname|monthly_downloads|has_repo.has_repois1when a public source repository is linked and0when not.registry_names: the names that really exist on the package index.- Return one verdict per record, in order:
"malformed","hallucinated","unvetted"or"approved".
Rules the tests check. Use the first that applies:
"malformed": the record does not split on|into exactly 3 fields, or the name is empty, or the downloads field is not one or more digits from 0 to 9, orhas_repois not exactly0or1."hallucinated": the name is not on the registry. Compare names the way the package index does, on both sides: lowercase the ASCII letters and treat_as-. Nothing else changes: no trimming, and other characters stay as they are."unvetted": fewer than 1000 monthly downloads, orhas_repois0."approved"otherwise.
Examples
screen_dependency_suggestions(records: list[str], registry_names: list[str]) -> list[str]Example 1
Input
screen_dependency_suggestions(["bleach|52000000|1", "htmlsanitizer-pro|0|0"], ["bleach", "nh3", "html5lib"])Output
["approved", "hallucinated"]Example 2
Input
screen_dependency_suggestions(["nh3|1200|1", "sanitize-html-pro|140|1"], ["nh3", "sanitize-html-pro"])Output
["approved", "unvetted"]Example 3
Input
screen_dependency_suggestions(["HTML5Lib|9000|1"], ["html5lib"])Output
["approved"]