ComfyUI Node

HT Text Cleanup

Messy prompt text in, one clean string out — HT Text Cleanup

By ArtHommage·Created 2 years ago·Updated about a year ago· 4
HT Text Cleanup
    • cleaned_text
    input_text
    preserve_period_spacetrue
    preserve_linebreaksfalse
    aggressive_cleanupfalse

    Prompts arrive messy. They're copy-pasted from civitai pages, assembled by wildcard systems, stitched from node text boxes with inconsistent spacing, or dragged out of OCR'd notes. And while CLIP will tolerate "a beautiful,detailed portrait" with its doubled spaces and stray commas, the inconsistency quietly shifts your results. HT Text Cleanup (from the HommageTools pack) is a normalization node: one string in, one consistently formatted string out, so the text your sampler sees is predictable.

    How it works

    The node runs your input_text through a series of cleaning passes: whitespace normalization, punctuation cleanup, and final formatting passes, with three toggle knobs controlling what gets preserved:

    • preserve_period_space (default true) - keeps a single space before periods. This is the one you usually want on; the classic cleanup bug is collapsing "word . word" into "word.word" and gluing sentences together.
    • preserve_linebreaks (default false) - keep single linebreaks instead of collapsing everything to one line. Off by default, which is right for prompts (line structure is usually accidental) but wrong if you're feeding it structured text.
    • aggressive_cleanup (default false) - apply stricter rules: more aggressive punctuation fixes and normalization. Turn this on when the input is genuinely messy and you want maximum scrubbing; leave it off when you don't want the node second-guessing your intentional styling.

    The output is a single cleaned_text string, ready for a CLIP Text Encode or any downstream text consumer.

    When you'd actually use it

    Three realistic jobs. First, standardizing prompts before encoding - if you generate from a mix of sources (manual typing, wildcard expansions, imported workflows), cleaning first makes your results far more consistent, which matters when you're comparing outputs across prompts. Second, scrubbing text before it flows into other text nodes: extracted parameters, filenames, anything where stray whitespace or double punctuation creates brittle downstream matching. Third, batch jobs - the exact same cleanup pass applied to a whole dataset (e.g., captions you're about to train on) instead of eyeballing each string.

    Installing it

    HommageTools install, once:

    cd ComfyUI/custom_nodes
    git clone https://github.com/ArtHommage/HommageTools.git
    cd HommageTools
    pip install -r requirements.txt
    

    Restart ComfyUI, or ComfyUI Manager → "HommageTools". Pure string processing, no models, no extra dependencies. The pack's perpetual-alpha disclaimer is low-stakes here - worst case, the cleanup rules shift in an update and you tweak a toggle.

    Where it bites

    The preserve_linebreaks default is the trap. If you feed it caption text or multi-line structured content expecting the structure to survive, it won't - the node collapses to a single line unless you flip that toggle. And aggressive_cleanup can fight you on intentional punctuation (stylized prompts with deliberate ... or -- markers can get "fixed"). If a prompt comes out subtly different than you wrote it, check that knob before blaming the encoder. Rule of thumb: preserve_period_space on, aggressive off, and only turn on linebreak preservation when you actually have multi-line structure worth keeping.

    CategoryHommageTools

    Inputs (4)

    NameTypeDefaultDescription
    input_textSTRING
    preserve_period_spaceoptBOOLEANtrue
    preserve_linebreaksoptBOOLEANfalse
    aggressive_cleanupoptBOOLEANfalse

    Outputs (1)

    NameTypeDescription
    cleaned_textSTRING