Nodes/VLM_nodes/Text Clean
ComfyUI Node Runs on cloud

Text Clean

Text Clean

By gokayfem·Created 3 years ago·Updated 9 days ago· 583
Text Clean
    • text
    • diagnostics_json
    text
    unicode_normalizationNFC
    whitespaceNormalize line endings
    trim_edgestrue
    remove_outer_markdown_fencefalse
    deduplicate_linesfalse
    max_characters0

    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) or NFKC, or None to 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; 0 keeps 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.

    CategoryVLM Nodes/Text/Transform

    Inputs (7)

    NameTypeDefaultDescription
    textSTRING
    unicode_normalizationCOMBONFC3 options: NFC, NFKC, None
    whitespaceCOMBONormalize line endings4 options: Normalize line endings, Preserve, Collapse horizontal, Collapse all
    trim_edgesBOOLEANtrue
    remove_outer_markdown_fenceBOOLEANfalse
    deduplicate_linesBOOLEANfalse
    max_charactersINT00–100000000 keeps the complete text.

    Outputs (2)

    NameTypeDescription
    textSTRING
    diagnostics_jsonSTRING