Fix UTF-8 String
Scrub the mojibake — Fix UTF-8 String turns garbled text into clean ASCII
- string
You know that text - the prompt that came out of a translation tool, a tag list scraped from a site that shipped full-width characters, a filename that looks like the font ate it. Hello,world type garbage, or accented characters your model's tokenizer chokes on. Fix UTF-8 String is the cleanup pass: it normalizes common UTF-8 punctuation and accented letters down to ASCII equivalents and strips whatever non-ASCII survives.
Let's be precise about what it does and doesn't do, because the pack's README oversells it. The README says it "repairs malformed UTF-8 byte sequences (e.g., mojibake from encoding mismatches)." Read the source and the truth is more modest: it runs a replacement table - full-width ( → (, , → ,, curly quotes to straight ones, é → e, ß → ss, and so on - then drops any character whose ordinal is still above 127. That's transliteration-plus-stripping, not byte-level mojibake repair. If your text is genuine double-encoded garble (the é kind), this node won't magically reverse the encoding. What it's genuinely great at is normalizing a prompt or tag list that picked up foreign punctuation or accented characters somewhere along the way.
The mechanism, in the source, is a two-step pass. First replace_special_characters walks each character: anything already in the printable ASCII set is kept as-is, anything in the replacement dictionary is swapped for its ASCII equivalent, and anything else falls through. Then remove_special_characters does a final pass that keeps only characters with ordinals under 128. Result: a clean ASCII string you can hand to any text encoder or filename function.
The inputs and output are minimal:
- string - the text to clean.
- string - the normalized ASCII result.
Where it fits in a workflow: anywhere a string enters the graph from outside and you want it squeaky-clean before it hits CLIP or a save path. The pack's SEARCH_ALIASES are telling - "clean text" and "ascii sanitize" - that's the honest job description. If you're doing multilingual prompt batches or importing tag lists from sources that aren't strict ASCII, put this between the import and the text encoder and you'll stop chasing weird tokenizer behavior.
Honest caveats: it strips non-ASCII rather than translating it, so a Chinese or Japanese prompt loses all its non-Latin content - use this only where ASCII is the goal. And the replacement table is finite; exotic characters you care about might not be in it and would just get dropped. For English-with-accented-characters cleanup, it's exactly right.
Install is the standard pack path: ComfyUI Manager → search ComfyUI-FairLab → install → restart:
cd ComfyUI/custom_nodes
git clone https://github.com/yanhuifair/ComfyUI-FairLab.git
cd ComfyUI-FairLab
pip install -r requirements.txt
Restart, search "Fix UTF-8 String" or "clean text". No models, no dependencies beyond the pack - pure string processing.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| string | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| string | STRING | — |