Nodes/Sage Utils/Clean Text
ComfyUI Node

Clean Text

The whitespace-and-comma tidy-up your prompts keep needing

By arcum42·Created 2 years ago·Updated 21 days ago· 33
Clean Text
    • cleaned string
    str

    Your prompts get messy for boring reasons: a wildcard leaves a double space, a LoRA keyword arrives with a trailing comma, a copied block has stray newlines and , , pairs. None of that changes what the model generates, but all of it looks bad when it lands in the PNG metadata you're stamping on every image. Clean Text is the pack's text tidy-up: one multiline string in, one cleaned string out.

    Mechanically it calls the same clean_text utility that the pack's CLIP encode nodes use under the hood (the clean toggle on Dual CLIP Text Encode is this function applied before encoding). What it does is normalize the string - collapsing extra whitespace, fixing doubled separators and stray commas, tightening punctuation. It's a formatting pass, not a rewrite: it won't touch your words or reorder anything, and it doesn't add or remove meaning. If you want prompt enhancement, that's the LLM tab's job; this node is purely about hygiene.

    Where it earns its keep is in the metadata pipeline. Sage Utils is built around embedding clean, Civitai-readable prompts into your images, and there's nothing worse than opening an image in Civitai and seeing my prompt ,, extra, , details in the params. Sticking a Clean Text between your prompt source and the metadata constructor fixes that permanently - and since it's also the exact cleaning the encoders apply, your metadata ends up matching what was actually encoded. That consistency is the quiet win: the stamped text and the encoded text agree.

    It's also just a nice node to keep in your back pocket for any string manipulation. Feed it a filename list, a tag dump from the Prompt Builder, output from an LLM - anything that should read cleanly as one line. One input (str, multiline), one output (cleaned string). Nothing to configure, nothing to break.

    Worth a sentence on expectations: this is aggressive enough to be called "clean", so don't use it on text where whitespace is meaningful (poetry, lyrics, formatting you want preserved). For prompts and tags it's exactly right.

    Install

    ComfyUI Manager → search Sage Utils → install → restart. Manual:

    cd ComfyUI/custom_nodes
    git clone https://github.com/arcum42/ComfyUI_SageUtils.git
    cd ComfyUI_SageUtils && pip install -r requirements.txt
    

    Restart ComfyUI. No model files, no keys; the pack's only Python dependency is dynamicprompts. If you've used the pack's CLIP encode nodes with clean on, you already know what this output looks like.

    CategorySage Utils/text/helper

    Inputs (1)

    NameTypeDefaultDescription
    strSTRINGText input to clean using the configured clean_text utility.

    Outputs (1)

    NameTypeDescription
    cleaned stringSTRINGOutput value for cleaned_string.