Sanitize Filename (Oli)
Make your file names safe before save nodes choke on them
- prefix
- path
- filename
Sanitize Filename (Oli) takes a string - a prompt, a title, a generated tag - and turns it into something Windows, macOS, and your save node will all accept. It's the boring-but-necessary node you reach for the first time a generated file fails to write because the filename contained a /, a :, or a control character that made the OS (or your importer) throw up.
How it works
It's a whitelist filter, not a "remove the bad characters I know about" filter. Anything that isn't explicitly allowed gets replaced:
- ASCII letters and digits always survive.
- Hyphens survive.
- Spaces survive if
allow_spacesis on (default). - Forward slashes survive if
allow_slashis on (default) - treated as path separators, so a"folder/file"input builds a real subpath. - Unicode survives only if
allow_unicodeis on. Off (the default), diacritics are transliterated via NFKD: à→a, é→e, ü→u, ñ→n. Characters with no ASCII decomposition get dropped.
Everything else becomes replacement (default _; must be a single non-alphanumeric ASCII character - invalid values fall back to _). Runs of two or more separators collapse to the highest-priority one (/ > - > space > replacement), so a messy name doesn't become a run of underscores. It also normalizes backslashes to forward slashes, trims junk from the edges, and truncates to a byte limit.
Inputs that matter
- filename - the name to sanitize (may include
/separators). - folder - an optional prefix path; slashes are always allowed here.
- extension - with or without the leading dot; it's stripped and re-added cleanly.
- max_length - caps the filename component at N UTF-8 bytes (default 240). The default deliberately leaves room for the counter and extension that save nodes append - the OS limit is 255 bytes. Note it's bytes, not characters, so accented letters (2 bytes each) count double.
- replacement - the substitution character.
Outputs
Three strings, so you can feed whichever a save node wants: prefix (folder/filename without the extension - the thing Save Image-style nodes take), path (folder/filename.ext), and filename (just filename.ext, no folder).
Install & gotchas
cd ComfyUI/custom_nodes
git clone https://github.com/magicoli/comfyui-oli-prompt-tools
…or ComfyUI Manager → Oli Prompt Tools, then restart. No dependencies.
It's one of the pack's newer nodes, so it's missing from the README's node table - it loads fine, the docs just lag the code. And a friendly warning: because allow_unicode defaults to off, a filename full of non-Latin script loses most of its characters. If your prompts are in Japanese or Arabic, turn allow_unicode on or you'll end up with a pile of underscores.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| filenameopt | STRING | The filename to sanitize. | |
| folderopt | STRING | The folder path to sanitize. | |
| extensionopt | STRING | File extension (with or without leading dot). | |
| allow_spacesopt | BOOLEAN | true | — |
| allow_slashopt | BOOLEAN | true | Preserve / as path separator in the filename input. |
| allow_unicodeopt | BOOLEAN | false | If disabled, diacritics are transliterated via NFKD: à→a, é→e, ü→u, etc. |
| max_lengthopt | INT | 2400–4096 | Max bytes for the filename component (0 = no limit). Default 240 leaves room for the counter and extension that save nodes typically append. OS limit is 255 bytes. |
| replacementopt | STRING | _ | Character used in place of disallowed characters. Must be a single non-alphanumeric ASCII character; invalid values fall back to _. |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| prefix | STRING | — |
| path | STRING | — |
| filename | STRING | — |