Model Scanning Catches Dangerous Artifacts Before They Load
Model scanning inspects serialized ML artifacts before a runtime loads them. A useful gate identifies executable payloads, unsafe deserialization paths, suspicious imports, and format-specific risk, then preserves the scan result beside the artifact digest. It covers the model supply chain. Runtime authorization still needs a separate control on live LLM traffic.

Model scanning opens a machine-learning artifact before the production runtime does and looks for executable content and unsafe serialization constructs. It also looks for suspicious imports and format-specific indicators. The timing matters. A pickle file can trigger code while it loads, before an inference endpoint receives its first HTTP request. I treat that boundary as a release gate: record the artifact digest, scan the exact bytes that will ship, and block promotion when the scanner cannot establish an acceptable result.
Scanning governs an artifact moving through build and deployment. Runtime AI security governs requests after a service starts accepting traffic. A serious program needs a named owner for each boundary.
TL;DR
- Run model scanning against the exact artifact digest before any runtime loads it.
- Treat pickle and similar executable serialization formats as code-bearing inputs, with provenance and isolation requirements.
- Store the scanner version, ruleset, result, and artifact digest as release evidence. Preserve any exceptions beside them.
- Keep artifact scanning separate from identity-aware policy on live LLM requests. The controls cover different paths.
Model scanning starts before deserialization
Serialization packages model state so another process can reconstruct it. Some formats can also represent objects whose reconstruction invokes code. Hugging Face's current Pickle Scanning documentation warns that loading a pickle file can permit arbitrary code execution. It recommends trusted publishers and signed commits, and it exposes detected imports for inspection.
That mechanism sets the order of operations. Downloading an artifact into a quarantine location is one action. Loading it into Python is another, much more consequential action. The scanner must inspect the first state without crossing into the second. If a security tool imports the artifact through the same unsafe loader it is supposed to police, the scan has already lost the boundary.
A useful gate binds the result to a cryptographic digest. The grey scan result in a build console should identify the same bytes that the deployment controller later promotes. Repacking or replacing the artifact after the scan invalidates that evidence.
The scanner has a narrow and valuable job
Protect AI's open-source ModelScan project describes support for H5 and Pickle formats. It also supports SavedModel and scans these formats for unsafe code. Its explanation of serialization attacks is blunt: malicious code added during saving can execute when a loader reconstructs the model. This is a concrete inspection job, bounded by the parser's understanding of each format.
The gate should preserve the detected format, triggered objects or imports, scanner and ruleset versions, inspected digest, and exception approval. Every exception also needs an expiry date.
I would reject any model security review that ends with a green badge and lacks the artifact digest. The badge proves that something passed. It fails to prove that production loaded the same thing.
AI supply chain attacks also reach dependency indexes, build scripts, containers, and plugin packages. Artifact scanning contributes one gate inside that broader release path. It cannot establish the integrity of every dependency surrounding the model.
Promotion needs provenance and isolation
The promotion controller should accept artifacts only from approved registries or repositories. A trusted source narrows exposure, while a digest pins the exact object. Signatures can bind publisher identity to an artifact, and an isolated scanner limits the damage if parsing hits hostile content. The final release decision belongs outside the training notebook and outside a data scientist's laptop.
PyTorch documented this separation after the torchtriton dependency compromise. A malicious package used the same name as a dependency on PyPI, whose index took precedence over PyTorch's nightly package index. That incident targeted the installation path around the framework rather than model weights. The lesson for a scanning workflow is precise: artifact checks need dependency and provenance controls around them because a clean model file can still arrive through a compromised environment.
Exceptions need the same discipline. A security owner can approve a blocked construct for a named digest and release. The approval also needs an expiry date. An open-ended waiver attached to a filename such as final-model.pkl will outlive the bytes it was meant to cover.
Runtime controls begin after deployment
Once the artifact is loaded and exposed behind an HTTP endpoint, a different control problem begins. The runtime receives prompts, retrieved context, identity claims, tool requests, and model responses. Model scanning cannot decide if a finance analyst may send a particular earnings document to that endpoint. It also cannot redact PII or produce a per-request authorization record because none of those inputs existed at build time.
The inverse boundary matters too. An HTTP gateway sees live traffic. It is blind to a malicious pickle executing inside a build worker before the service starts. The comparison of DeepInspect and Protect AI maps these placements in more detail: model-supply-chain scanning belongs in the artifact pipeline, while request enforcement belongs on the live call path.
Release evidence says which artifact was admitted and under which scan policy. Runtime evidence identifies the authenticated caller and the applicable data classification. It also records what the request policy decided.
DeepInspect
DeepInspect covers the runtime side of this control split. It sits between authenticated users or agents and HTTP-based LLM endpoints, evaluates prompt and response traffic against identity-aware policy, and creates a per-decision audit record. It does not scan model files or execute artifact parsers.
Put the artifact scanner in the build and promotion path. Put DeepInspect on the live AI request boundary. The resulting evidence connects an approved deployment to the people and agents permitted to use it, without claiming that one control can inspect both surfaces.
Book a technical deep dive at deepinspect.ai.
Frequently asked questions
- Does model scanning make an untrusted pickle safe to load?
A clean result reduces the known risk covered by that scanner and ruleset. It cannot prove that an untrusted pickle is harmless. Parser coverage and scanner defects remain relevant. New exploit techniques do too. Use trusted publishers, pinned digests, signatures where available, an isolated scan environment, and a release approval that records residual risk. For higher-risk workloads, prefer a format whose loader does not reconstruct executable Python objects when the deployment stack supports it.
- Where should the model scan run?
Run it after the artifact enters a controlled quarantine location and before conversion, registration, packaging, or production loading. Repeat the scan when a conversion or packaging step changes the bytes. Bind every result to the resulting digest rather than the filename. The deployment controller should verify the approved digest before promotion, which prevents a later replacement from inheriting an earlier artifact's clean result.
- What belongs in the scan evidence record?
Record the artifact digest and source, the detected format, scanner version, ruleset version, start and completion times, findings, disposition, and any exception approval. Add the deployment or release identifier that consumed the result. This creates a traceable chain between the inspected object and the runtime release without pretending the scan describes subsequent user requests.
- Can an AI gateway replace model scanning?
An AI gateway operates after a service begins receiving HTTP requests. It can inspect prompt and response traffic, apply identity-bound policy, and record each decision. Model scanning runs earlier against the artifact and serialization path. The two controls have separate evidence, failure modes, and owners. Replacing either one with the other leaves a boundary uninspected.