# Building a clean copy The `sanitize` command reads a GGUF file and writes a new copy without any of the places where data can hide. The model in the new copy gives exactly the same answers, because its weights do not change. ```bash gguf-radar sanitize suspicious.gguf -o clean.gguf ``` The original file is never changed. The output must be a different file. ## What the clean copy changes The new file is rebuilt from its parts in a standard layout: - Everything after the last block of weights is dropped. - The padding between the metadata and the weights is filled with zeros. - Quantization blocks whose scale is zero can carry bytes that the model never uses. These bytes are set to zero, including the ordinary leftover bytes that a scan reports only as a note. In the formats with a second scale, a block whose first scale is zero and whose second scale is not loses only its values and keeps its scales. In `IQ4_NL` and `IQ4_XS`, a block that holds only the pattern that the quantizer writes for weights that are all zero is kept as it is. - Scales stored as negative zero are rewritten as ordinary zero in the `Q8_0` and `Q4_K` formats. The other formats keep them, because their quantizers write negative zero themselves. - If a metadata key appears twice, only the first copy is kept. Use `--keep-last-duplicate` to keep the last copy instead. None of these changes alter a value that the model uses. Negative zero and ordinary zero are the same number, and the cleared bytes in zero-scale blocks are multiplied by zero when the model loads, so their value never reaches the weights. The test suite confirms this by converting the weights of a test file back to numbers before and after the rebuild and checking that they are identical. ## Replacing or removing the chat template The rebuild keeps the chat templates as they are. If a template is the problem, you have two choices. A GGUF file can hold named templates, such as `tokenizer.chat_template.tool_use`, next to the default one, and both choices cover them. Replace it with a template you trust, such as the one published with the original model: ```bash gguf-radar sanitize suspicious.gguf -o clean.gguf --replace-template original_template.jinja ``` Or remove it completely: ```bash gguf-radar sanitize suspicious.gguf -o clean.gguf --strip-template ``` A model without a chat template still works in most runtimes, but it may format conversations differently. Replacing the template with the original one is usually the better choice. With `--replace-template`, the default key `tokenizer.chat_template` holds the new text. It is added if the file had no default template. Every named template is removed, because the replacement is the only template that you vouched for. A runtime that does not find a named template uses the default one. With `--strip-template`, the default and all named templates are removed. The array `tokenizer.chat_templates` lists the names of the named templates. It is removed together with them, so that it never lists a name without a template. A rebuild without either option keeps all templates and the array as they are. ## Reading the summary The command prints what it changed. The summary below is shortened. The full summary also gives the sizes of the input and output files, the bytes reclaimed, the alignment, the scales stored as negative zero that were rewritten and the duplicate keys that were removed. ```text Sanitized GGUF written to: clean.gguf Slack non-zero bytes wiped: 0 B EOF overlay bytes removed: 4,093 B Dead blocks canonicalized: 0 Chat template action: stripped Named template removed: tokenizer.chat_template.tool_use Template names removed: tokenizer.chat_templates Model weights: unchanged, only unused bytes were cleared ``` The two lines about named templates appear only when the file held them. In the JSON summary, they are `named_templates_removed` and `template_names_removed`. Add `--json report.json` to save the same summary as JSON. Nothing is printed to the terminal then. Use `--json -` to print only the JSON. ## Scan the result Scan the new file before you use it: ```bash gguf-radar scan clean.gguf ``` A rebuild removes hidden data, but it does not make a harmful template safe. If the scan still reports template findings, replace or remove the template.