Nodes/Comfyui-General-API-Node/Prompt Cleaner (FeiMao-326)
ComfyUI Node

Prompt Cleaner (FeiMao-326)

A last-pass scrub for messy prompts — dedupe, fix commas, drop empty brackets

By FeiMao-326·Created 12 months ago·Updated 5 months ago· 0
Prompt Cleaner (FeiMao-326)
    • text
    text
    remove_duplicate_tagstrue
    clean_bracketstrue

    If you assemble prompts from multiple sources - an LLM, a wildcard, a template, some tags you typed in 2024 - they arrive with scars. Duplicate tags, , , double commas, stray () left behind when a wildcard picked nothing, inconsistent spacing. This node is the janitor: it takes your messy text, normalizes the punctuation, drops the duplicates, and hands back a clean comma-separated tag list ready for the text encoder.

    How it works

    Inputs are text (multiline), plus two toggles: remove_duplicate_tags and clean_brackets, both on by default. The pipeline runs in a specific order:

    1. Newlines are turned into commas and multi-comma runs collapse to a single , - so multi-line prompt blocks become one flat tag list.
    2. The text is split on commas, each tag trimmed.
    3. With remove_duplicate_tags on, duplicates are removed case-insensitively while preserving first-seen order. Masterpiece, masterpiece becomes Masterpiece, not masterpiece.
    4. With clean_brackets on, empty bracket pairs like (), ( ), [] are stripped out, and any comma runs created by that removal get collapsed again.

    The result is a single text string with the tags joined by ", " and leading/trailing commas trimmed. It's a destructive-ish transform - if your prompt legitimately contains (word:1.2) weight syntax, note that only empty brackets are removed, so weighted terms survive. But this node is clearly built for the modern tag-list world, not the SD1.5 (word:1.2) world, and it assumes commas are your structure.

    Where it fits

    The author's framing is exactly right: use it as the "final touch" before KSampler. If an LLM is generating or rewriting prompts, its output will contain exactly the kind of junk this cleans - duplicate adjectives, weird whitespace, artifacts from template substitution. Slap one of these between your prompt-assembly section and the CLIP Text Encode and your negative space stops being "silently worse prompts."

    One honest limitation: "cleaning" here means structural cleanup, not semantic quality. It won't fix a tag that's wrong for your checkpoint, and it can't tell 1girl from 2girls. Pair it with a real prompt-engineering pass (matching tags to the model's vocabulary) rather than expecting it to save a badly-written prompt.

    Inputs and outputs

    • text (STRING, multiline) - the prompt to clean.
    • remove_duplicate_tags (BOOLEAN) - dedupe case-insensitively, keep first occurrence.
    • clean_brackets (BOOLEAN) - strip empty (), (), [].
    • text (STRING) - the cleaned prompt.

    Installing

    It's one of the sixteen nodes in the FeiMao-326 pack (category "FeiMao-326"), so install the pack once:

    cd ComfyUI/custom_nodes
    git clone https://github.com/FeiMao-326/Comfyui-General-API-Node.git
    cd Comfyui-General-API-Node
    pip install -r requirements.txt
    

    Restart ComfyUI, then Add Node → FeiMao-326 → Prompt Cleaner. ComfyUI Manager users can search "Comfyui-General-API-Node" instead. Dependencies are just openai, numpy, Pillow, requests - nothing heavy.

    CategoryFeiMao-326

    Inputs (3)

    NameTypeDefaultDescription
    textSTRING
    remove_duplicate_tagsBOOLEANtrue
    clean_bracketsBOOLEANtrue

    Outputs (1)

    NameTypeDescription
    textSTRING