How model-file-guard works
Every time someone shares a trained model, they share a file. If that file is a pickle (the default for scikit-learn, joblib and older PyTorch code), loading it can run any command its author wanted. A product-recommendation model downloaded from a hub, or a “fixed” model a freelancer sends back, can open a shell on your server the moment your app loads it.
model-file-guard reads the file the way Python would, without running anything, and tells you exactly what it would do: would run: os.system('curl ... | sh'). Files that only rebuild tensors and plain data pass. Files that need your own code are marked for review, so you can allow just those classes.
It also checks the formats that are supposed to be safe. A safetensors file with extra bytes after its tensors, a GGUF file with impossible sizes, a chat template that reaches into Python internals, an ONNX model that reads ../../etc/passwd: these are all real attack shapes, and each has its own check.
Try it
You need Python 3.9 or newer. No other packages are needed.
pip install model-file-guard
model-file-guard path/to/models
Scan a Hugging Face repo before you download it:
model-file-guard hf OWNER/REPO
And check whether your installed PyTorch, Keras, ONNX or llama-cpp-python has a known model-loading flaw:
model-file-guard env
Why I built it
My research is on efficient and secure machine learning inference, much of it with gradient-boosted tree models saved as joblib files. The popular scanner could not read an ordinary scikit-learn joblib file with arrays in it, and blocklist scanners keep being bypassed by imports nobody listed. I wanted a scanner that reads files exactly as the loaders do, allows only what real models need, and stays free.
Free and open source under the MIT license. Not affiliated with PyTorch, Hugging Face or any scanner vendor. Need help securing your AI supply chain? Book a call.