Text Clean
Text Clean
- text
- diagnostics_json
Model output is messy, and vision-language output is messier. There's the trailing whitespace, the markdown fences the model wrapped around its answer even though you didn't ask, the weird Unicode that looks identical to the character you wanted but isn't, and the 40-line caption that's really 5 lines repeated. VLMTextClean is the node that normalizes all of it - a single dependency-free scrubber that lives in the pack's Text toolkit precisely so you don't need to bolt on another text-handling pack for this.
You reach for it at the point where a model's string is about to flow into something that needs clean input: a template, a batch splitter, an API call, a file name. One pass through this node and the text is predictable in a way raw model output never is.
What it actually does
Seven toggleable cleanups, all in one node:
unicode_normalization-NFC(default) orNFKC, orNoneto skip. This is the subtle one that saves real pain: model output often contains composed vs. decomposed characters, and a string that looks right fails a byte-exact comparison. NFC/NFKC makes it canonical.whitespace- normalize line endings, collapse horizontal whitespace, collapse everything, or preserve as-is.trim_edges- strip leading/trailing whitespace.remove_outer_markdown_fence- strip the enclosing```block a model wrapped around its answer.deduplicate_lines- drop repeated lines (handy when a VLM repeats its answer 4 times).max_characters- deterministic length cap;0keeps everything.
Everything runs locally - no network, no model, no tokenizer. Deterministic is the operative word: feed it the same text and the same settings and you get the identical output, every run, which is what you want when text feeds downstream automation.
Inputs and outputs
Only text is required; every other input has a sensible default and you flip on what you need. It's also fine to set deduplicate_lines off unless you specifically want it - it can mangle legitimate repeated content.
Outputs are text (the cleaned string) plus a diagnostics_json describing what was done - useful when you're debugging why a downstream node is seeing something unexpected.
Install
Part of ComfyUI VLM Nodes (gokayfem/ComfyUI_VLM_nodes). ComfyUI Manager → search "VLM Nodes", or clone manually:
cd ComfyUI/custom_nodes
git clone https://github.com/gokayfem/ComfyUI_VLM_nodes
python -m pip install -r ComfyUI/custom_nodes/ComfyUI_VLM_nodes/requirements.txt
Run pip with ComfyUI's Python and don't let the repo install its own torch. The text toolkit has no model dependencies at all - it's pure Python string handling, so it works on any setup, CPU or GPU.
Gotchas
Don't over-clean. max_characters truncates deterministically but blindly, so if you're cutting text to fit a context window, remember it cuts characters, not tokens - use VLMTextInspect to check the actual budget first. And remove_outer_markdown_fence only removes an enclosing fence; if your model writes code and a fence, you may want VLMTextSplit or a template afterward rather than expecting one node to make prose out of an answer that was never clean.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | — | |
| unicode_normalization | COMBO | NFC | 3 options: NFC, NFKC, None |
| whitespace | COMBO | Normalize line endings | 4 options: Normalize line endings, Preserve, Collapse horizontal, Collapse all |
| trim_edges | BOOLEAN | true | — |
| remove_outer_markdown_fence | BOOLEAN | false | — |
| deduplicate_lines | BOOLEAN | false | — |
| max_characters | INT | 00–10000000 | 0 keeps the complete text. |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| text | STRING | — |
| diagnostics_json | STRING | — |