Skip to main content

weightguard

Security scanner for ML model artifacts. Point it at a Hugging Face repo, a git URL, or a local path, and it flags known artifact-level risks — malicious pickle/PyTorch payloads, Keras Lambda-layer code injection, ONNX custom-op RCE surface, and anomalous/crafted GGUF headers — with a severity and a concrete mitigation for each finding.

Model files are not inert data. Several common serialization formats can embed code that executes the moment the file is loaded, before any inference happens. weightguard is a static, pre-load check you run before trusting a downloaded model.

Install

pip install weightguard

Usage

# Hugging Face repo
weightguard scan https://huggingface.co/<org>/<repo>

# git repo
weightguard scan https://github.com/<org>/<repo>.git

# local path
weightguard scan /path/to/model

# CI gate — exit non-zero only above a severity threshold (default: HIGH)
weightguard scan <target> --fail-on CRITICAL

Exit codes: 0 clean, 1 a finding at/above --fail-on, 2 target could not be resolved.

Use as a library

The CLI is a thin wrapper over the same public API — import it directly to scan programmatically (CI scripts, pre-deploy hooks, MLOps pipelines):

from weightguard import scan, Severity, UnresolvableTarget

try:
    report = scan("https://huggingface.co/<org>/<repo>")  # or a git URL / local path
except UnresolvableTarget as exc:
    raise SystemExit(f"could not resolve target: {exc}")

for finding in report.findings:
    print(finding.severity, finding.detector, finding.title, finding.file)

if report.fails(Severity.HIGH):
    raise SystemExit("blocking: high-severity finding in model artifact")

Lower-level pieces are also exported if you want to resolve and scan separately, or scan a pathlib.Path you already have on disk:

from weightguard import resolve, scan_path

path = resolve("https://github.com/<org>/<repo>.git")  # downloads, returns local Path
report = scan_path(path)

scan_path never executes or deserializes the target files — it's pure static analysis, safe to run against untrusted artifacts.

What it checks today

Format Detector Technique
Pickle / PyTorch (.pkl, .bin, .pt, .pth) Fickling AST analysis Detects arbitrary-code-execution opcode chains; resistant to the malformed-opcode-stream evasion that defeats denylist scanners
SafeTensors Format check Flags files that fail to parse as valid SafeTensors (renamed/spoofed files)
Keras (.h5, .keras) Lambda-layer check Flags Lambda layers, which embed a marshalled Python function executed on load
ONNX Custom-op check Flags graphs referencing non-standard operator domains (native-code load surface)
GGUF Header/KV anomaly check Flags malformed headers, oversized KV metadata, unknown quantization types, and tensor sizes inconsistent with the file

Development

uv sync
uv run pytest -q

License

MIT

Metadata

Release files for weightguard 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for weightguard 0.1.2
File Size Uploaded
weightguard-0.1.2.tar.gz 9.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for weightguard 0.1.2
File Interpreter ABI Platform
weightguard-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 23.8 kB

Release files / weightguard-0.1.2.tar.gz

Download URL weightguard-0.1.2.tar.gz
Size 9.1 kB
Tags Source
SHA-256 checksum
How to use checksums
7e52604608e32d995205f0f483ac065d39b8ab2d73986fb3e0734275a62bd8e8
BLAKE2b-256 checksum
How to use checksums
6ab166ce6b569265f08ddeb5b2a4b0bc659fe795790da35996cd62db67fff577
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Release files / weightguard-0.1.2-py3-none-any.whl

Download URL weightguard-0.1.2-py3-none-any.whl
Size 14.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
39dc514b4cd7bd947cce0da1922149086e8c116a0f95e097f833ba50d90de823
BLAKE2b-256 checksum
How to use checksums
d06dd7c7c4834e21001be56e97b2a75218d79df2efe138245d13280840b98ac0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Release history Release notifications | RSS feed

0.2.0

2 release files

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page