Nodes/WAS Node Suite v3/Prompt Tag Cleanup
ComfyUI Node Runs on cloud

Prompt Tag Cleanup

Tidy a prompt's tags — dedupe, sort, cap — without mangling emphasis

By WASasquatch·Created 3 years ago·Updated 4 days ago· 1,844
Prompt Tag Cleanup
    • text
    • tags
    • tag_strings
    • count
    • removed
    text
    delimiter,
    join_with,
    dedupetrue
    ignore_casetrue
    ignore_emphasistrue
    keep
    remove_emptytrue
    collapse_whitespacetrue
    sort
    limit0

    Prompts arrive messy. A concatenated pile of tags has duplicates, stray commas from unconnected inputs, and line breaks that become part of a tag if you're not careful. Prompt Tag Cleanup splits that mess into tags, drops what you don't want, optionally sorts and caps the list, and joins it back up - while correctly treating emphasis like (tag:1.4) as the same tag as the plain spelling. That last bit is the part that separates it from a naive string dedupe.

    It's the polite-bouncer node: most of what it does is invisible until you wire it into the path and realize your prompt stopped growing a copy of every tag on every concat. If you build prompts from multiple Text Concatenate branches - a subject block plus a style block plus a quality block - you've almost certainly shipped duplicates without noticing, because the eye skips repeated words. This node notices.

    The switches that matter

    • delimiter - what separates tags in the incoming text. The default , treats comma-separated tags correctly. Leave it empty and every word is its own tag, which is rarely what you want.
    • dedupe / ignore_case / ignore_emphasis - the deduping trio. ignore_case on means Neon Glow and neon glow are one tag; ignore_emphasis on means (neon glow:1.4) and neon glow are one. The tooltip's suggested combo - emphasis ignored, keep set to last - keeps the weighted spelling when a duplicate exists, so your (tag:1.4) survives the cleanup.
    • keep - first or last: which spelling of a duplicate survives.
    • remove_empty - drops tags holding nothing. This is what clears the run of bare commas an unconnected input leaves behind.
    • collapse_whitespace - runs of spaces, tabs and line breaks inside a tag become one space. This is what removes the accidental line breaks from a pasted multi-line prompt.
    • sort - none keeps written order (which preserves word order, the thing models actually read), or sort alphabetically/frequency if that's your workflow.
    • limit - keep at most this many tags, counted after everything else runs. 0 keeps all. Useful for trimming a prompt to fit a token budget.

    Outputs

    text is the tidied prompt, joined back up with join_with (the default , is ordinary prompt spelling; \n gets one tag per line). tags is the surviving set as one LIST for the list nodes, tag_strings is the same tags as a STRING list - a node reading it runs once per tag, which is how you'd render once per tag if that's the experiment. count and removed report what survived and what went, and removed of 0 means your prompt was already clean.

    The honest limits

    Deduping is exact-match based, not semantic - it won't notice cat and feline overlap, and nothing should expect it to. Sorting by anything other than none reorders your tags, and for tag-driven models word position matters, so only sort when you mean it. The node also operates on the string level: it doesn't know or care which checkpoint you're prompting, so the quality-tag ordering advice from your model's docs is still your job.

    Installing

    Ships in WAS Node Suite v3 - ComfyUI Manager (search WAS Node Suite v3) or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/WASasquatch/was-node-suite-comfyui
    

    Restart after cloning; needs ComfyUI 0.14.0+ and Python 3.10+. Like every node in the v3 pack it installs nothing extra - no pip packages, no downloaded weights - which is a deliberate change from the old v2 suite's heavy dependency load.

    Natural neighbors: put it after Prompt Parse when wildcard draws produce multi-tag lines you want deduped, and before a CLIP Text Encode when you want a clean, deterministic prompt string you can also save.

    CategoryWAS Suite/Text/Operations

    Inputs (11)

    NameTypeDefaultDescription
    textSTRINGThe prompt to tidy, as `a tabby cat,, a tabby cat`. Typed here, or wired in from whatever built it: Text Concatenate, a style selector, or a caption node.
    delimiterSTRING,What separates one tag from the next in the incoming text. Leave it empty to treat every word as its own tag. Type \n to split a prompt written one tag to a line.
    join_withSTRING, What is put between the tags on the way out. The default ', ' is the ordinary prompt spelling; type \n to get one tag per line, which is easier to read in a saved text file.
    dedupeBOOLEANtrueWhether a tag appearing more than once is reduced to one. The survivor keeps the position of the first occurrence, so tidying does not reshuffle the prompt.
    ignore_caseBOOLEANtrueWhether 'Neon Glow' and 'neon glow' count as the same tag. Off, both survive, which is only useful where a downstream tool treats capitalisation as meaningful.
    ignore_emphasisBOOLEANtrueWhether '(neon glow:1.4)' counts as the same tag as 'neon glow'. On with keep set to 'last' is the combination that collapses a prompt onto its weighted spellings, which is normally the intended one, the plain duplicate is usually what a second source contributed.
    keepCOMBOWhich of a set of duplicates survives. `first` keeps the earliest spelling, `last` the latest. Position is the first occurrence either way, so keeping the last spelling does not move the tag to the end of the prompt.
    remove_emptyBOOLEANtrueWhether tags holding nothing are dropped. This is what clears the run of bare commas an unconnected input leaves behind, which otherwise reaches the text encoder as it stands.
    collapse_whitespaceBOOLEANtrueWhether runs of spaces, tabs and line breaks inside a tag become a single space. This is what removes the line breaks a multi-line prompt box leaves in the middle of a tag.
    sortCOMBOHow the surviving tags are ordered. `none` keeps the order they were written in, which is what preserves the weight early tags carry in most encoders. The alphabetical orders make two prompts comparable by eye; `longest first` puts the descriptive phrases ahead of the single words.
    limitINT00–9999Keep at most this many tags, counted after everything else has run. 0 keeps all of them. Useful for trimming a caption model's output to the few tags worth keeping.

    Outputs (5)

    NameTypeDescription
    textSTRINGThe tidied prompt, joined back up with join_with.
    tagsARRAYThe surviving tags as one LIST, for Text List Get and the other list nodes.
    tag_stringsSTRINGThe same tags as a STRING list, so a node reading this runs once per tag, one render per tag, for instance. A prompt that tidies down to no tags leaves nothing to run on, so the nodes reading this socket stop and say so; the text output is still delivered, since an empty prompt is a valid one.
    countINTHow many tags survived.
    removedINTHow many entries the tidy-up took out, counting duplicates, empties and anything past the limit. 0 means the prompt was already clean.