Nodes/DJZ-Nodes/Prompt Dupe-Remover
ComfyUI Node

Prompt Dupe-Remover

When your prompt says 'beautiful' four times

By MushroomFleet·Created 2 years ago·Updated 5 months ago· 78
Prompt Dupe-Remover
    • STRING
    text
    preserve_casetrue

    PromptDupeRemover is the tiny housekeeping node you don't think you need until you've pasted together three prompts from three sources and the result says "beautiful" four times. It takes a text prompt, strips repeated words, and hands back a cleaner STRING. That's the whole job, and for a one-impression node it's a surprisingly well-made little tool.

    How it works is the interesting part, because naive dedup is a footgun. If you just split on spaces and drop seen words, you destroy punctuation and word order. This node instead splits while preserving punctuation, dedupes case-insensitively (so Beautiful and beautiful count as the same word), keeps the first occurrence of each word in place, and rejoins with spacing intact. The author's example: A beautiful sunset, beautiful clouds, beautiful sky, beautiful landscapeA beautiful sunset, clouds, sky, landscape. Punctuation stays, the repeated "beautiful" collapses to one, and the sentence still reads.

    The one real input besides text is preserve_case, a boolean that defaults to true - when on, the output keeps the original capitalization of the surviving words; when off, everything is lowercased. That matters more than it sounds: the first word of a sentence is usually capitalized, and if you lowercase a whole prompt that's been through an LLM, you're changing what the tokenizer sees. Default-on is the right call, and it's a signal the author thought about token-level behavior rather than just string matching.

    The honest take: for a single prompt you type by hand, you don't need this - you can just not type "beautiful" four times. Where it earns its place is the automation layer: wildcard expansions, concatenated prompt chains, caption loaders that join several sources, or an LLM prompt-builder that regurgitates phrases. In any of those, duplicate words accumulate invisibly and they're exactly the kind of bloat that pushes prompts past token budget on CLIP-encoded models (SDXL lineage still treats prompts as a token bag, so every wasted duplicate is a slot that could have held something useful). Slap this node after the concatenation point and it's set-and-forget.

    Worth knowing: it's case-insensitive dedup by default regardless of preserve_case, and it only handles exact word duplicates - "beautiful" and "beautifully" are different words, "sunset" and "sunsets" are different words. It's not a semantic cleaner; don't expect it to catch near-synonyms. If your prompt has red hair and red dress, both "red"s survive only if... actually no - they're the same exact word, so the second "red" gets dropped. Which is a behavior worth internalizing: this node dedupes words globally, not per-phrase, so a legitimate repeated word used in two different contexts (color + body part) will lose its second instance. Usually that's harmless in a prompt, occasionally it changes meaning. Keep it in mind if your prompt is heavy on adjectives reused across subjects.

    If it ever looks like the node is removing words you wanted, that's almost always it. No models, no deps beyond the pack install. Install: ComfyUI Manager → "DJZ-Nodes", or clone + pip install -r requirements.txt.

    CategoryCustom-Nodes

    Inputs (2)

    NameTypeDefaultDescription
    textSTRING
    preserve_caseBOOLEANtrue

    Outputs (1)

    NameTypeDescription
    STRINGSTRING