ComfyUI Node

Unique Tags

Dedupe your comma-separated prompt, then watch the order change

By yanhuifair·Created 2 years ago·Updated 3 months ago· 2
Unique Tags
    • string
    string

    The FairLab Unique Tags node removes duplicate entries from a comma-separated tag list. It's the cleanup step for prompts that got assembled from too many places: when you merge a base prompt, a style tag group, and a character set, the same tag shows up three times, and the result reads like a hoarder's closet. This node fixes that in one pass.

    Tag hygiene is more than cosmetic. The KB's prompt-engineering doc covers how tag-heavy models weight each token - duplicates are wasted context, and a bloated prompt pushes other things out. There's also the practical argument: nobody wants to manually scan 60 tags for repeats.

    How it works

    The mechanism is short and worth understanding because it dictates the behavior. The node:

    1. Splits the input on commas and strips whitespace (string_to_tags).
    2. Throws the tags into a Python set - dedup happens there.
    3. Joins the survivors back with ", " (tags_to_string).

    That's it. No model, no fuzzy matching, no case-folding.

    The input and the catch

    • string - a STRING socket, marked forceInput, so it must be wired. Output is a single string socket with the deduped list.

    The catch is the set. Python sets are unordered, so the order of the output is arbitrary - it is not the order you typed. The README's description ("Deduplicate entries in a tag list") undersells this: it doesn't just dedupe, it reorders. If tag order matters to you - and for some CLIP encoders and heavily-tagged models it genuinely does - this node will scramble your sequence.

    Also note what it doesn't do:

    • Case-sensitive. 1girl and 1Girl are different tags to it.
    • Whitespace is handled, punctuation isn't. "cat " and "cat" collapse (the strip catches it), but "cat," and "cat" are different strings.
    • No dedup within a single token. "blue blue sky" stays "blue blue sky".

    So treat it as: exact duplicate comma-separated entries, collapse them, order unknown. For a final-prompt clean pass that's usually fine. For order-critical prompts, run it early in the assembly or don't run it at all.

    When it's worth it

    • After merging tag groups from multiple sources.
    • Before a prompt goes into a CLIP encode, when you want a clean, compact list.
    • As part of a tag-engineering chain with the pack's Prepend Tags, Append Tags, and Exclude Tags nodes - all of which share the same split/join convention, so they compose cleanly.

    Installing it

    One pack, all nodes:

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

    Restart ComfyUI, or install via Manager by searching "ComfyUI-FairLab". This node has no dependencies of its own, so if the pack imported, it's there.

    CategoryFair/string

    Inputs (1)

    NameTypeDefaultDescription
    stringSTRING

    Outputs (1)

    NameTypeDescription
    stringSTRING