Text -> UTF-8 Cleaner
Invisible characters are sabotaging your prompts. This node removes them.
- clean_text
Copy text out of a PDF, a chat app, or a web page and it carries invisible passengers: zero-width spaces, non-breaking spaces, soft hyphens, byte-order marks, smart quotes, and the occasional arrow that renders fine for you and badly in a text encoder or a caption file. This node is the bouncer. It's one of the eight utilities in the Comfy Text Stats pack from scofano, and it's the one you reach for when pasted text misbehaves in ways you can't see.
What it does
It normalizes the text to Unicode NFC, maps common smart punctuation to ASCII equivalents (… → ..., –/- → -, curly quotes → straight), converts arrows like → to ->, collapses the various invisible Unicode spaces (non-breaking, thin, narrow) to regular spaces, and deletes zero-width characters, control characters, and BOMs. Crucially, it keeps all the valid Unicode letters - áéíóúç survive untouched. This is not an accent-stripper; it's an invisible-junk remover.
There's also a clever bit aimed at Windows. The node checks your system's preferred encoding, and on Windows - where the default is often a non-UTF-8 code page - it transliterates characters that can't be encoded, like ß → ss and æ → ae, so a downstream file write doesn't blow up with a charmap encode error. On a normal UTF-8 Linux or macOS setup that fallback almost never fires.
Input and output
One input, text (multiline). One output, clean_text - the sanitized string. That's the whole interface, which is exactly right for a cleaning node.
Why you'd reach for it
Two situations. First, caption and prompt hygiene: invisible characters in captions are silent gremlins - they don't render, but they're in the file and they can trip up exact-match logic or downstream processing. Second, it pairs naturally with Remove Empty Lines from the same pack: a line that looks blank but contains a zero-width space survives that node's strip() check (Python doesn't treat U+200B as whitespace), and this node is the one that actually deletes it. Run UTF-8 Cleaner first, then Remove Empty Lines, and your text is genuinely clean.
Installing it
It ships in the Comfy Text Stats pack. ComfyUI Manager: Manager → Custom Nodes Manager → search "Comfy Text Stats" → Install, then restart ComfyUI. Or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/scofano/comfy-text-stats
Restart after. No dependencies, no model downloads - the pack is stdlib-only, which is part of why installing it is painless.
Where people get burned
- Expecting it to strip accents. Feed it
oláand you getolá, notola. That's deliberate - valid Unicode is preserved. - The arrow and dash mappings are opinionated defaults. If you need
→to stay→, this is the wrong tool. - The transliteration fallback only kicks in when the system encoding can't represent a character, so on a normal UTF-8 machine you'll rarely see it - don't go looking for it.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| clean_text | STRING | — |