Nodes/ComfyUI-Text-Utility/Conditional Tag Processor
ComfyUI Node

Conditional Tag Processor

<ADD:...> and <REMOVE:...> commands

By watarika·Created 2 years ago·Updated 10 months ago· 3
Conditional Tag Processor
    • processed
    text

    Most prompt tweaking in ComfyUI is manual: type a prompt, run it, edit, rerun. Conditional Tag Processor is for when you want the prompt itself to carry the logic. You drop it in front of a text encoder and give it text that embeds commands like <REMOVE:solo:1girl> - and it rewrites the prompt before it ever reaches your CLIP encoder.

    It's one node in watarika's ComfyUI-Text-Utility pack, a small MIT-licensed grab-bag of text-handling nodes. Fair warning up front: this is the most experimental thing in the pack. The author's own docs say so - "experimental. Its syntax and behavior may change." So don't bake it into a workflow you can't touch for a year; do use it when one prompt template needs to serve several looks without you duplicating half the graph.

    How it works

    The node scans your text for angle-bracket directives and applies them left to right, then deletes the directive strings themselves:

    • <ADD:search:add_target> inserts tags. search says where (insert right after the matching item, or at the end if empty). add_target is a comma-separated list, inserted as written.
    • <REMOVE:search:remove_target> deletes tags. Omit search and it removes unconditionally.

    The matching logic is where it gets clever. It understands three shapes of "word": a plain item (blue eyes), a parenthesized item ((1girl, solo, smile:1.5) - matched per sub-word, and the whole parens vanishes only when every sub-word is gone), and the [CUT:white shirt:white] form that Danbooru-style workflows use for tag→prompt swaps (remove white shirt and the entire CUT item goes). ADD also de-duplicates: if a target word already exists anywhere, it isn't added twice. Search expressions support &, |, and () grouping - left-associative, so foo|bar&baz evaluates as ((foo|bar)&baz). Only uppercase ADD/REMOVE count, and matching is exact and case-sensitive.

    Inputs and outputs

    • text (STRING, multiline) - your prompt with the inline directives.
    • processed (STRING) - the rewritten, cleaned prompt. Wire it into a CLIP Text Encode, positive or negative.

    A realistic line:

    1girl, (solo), smile <REMOVE:solo:1girl> <ADD:1girl:masterpiece, (best quality:1.2)>
    

    Troubleshooting

    • Not adding? ADD skips words that already exist - including inside parentheses or CUT items. That's usually the "bug".
    • Not removing? Check for lowercase: <add:...> is ignored entirely.
    • Exact, case-sensitive matching means White Shirt won't touch white shirt. No substring or regex.
    • Commas inside () / [] are safe; only top-level commas split items.

    Easiest way to try it without wiring a node in: the pack's "Replace Variables and Process Wildcard (Loop)" node has a process_conditional_tags toggle that runs this exact pass at the end of its pipeline.

    Installing

    Install the whole pack via ComfyUI Manager (search "ComfyUI-Text-Utility", hit Install, restart), or from a terminal:

    cd ComfyUI/custom_nodes
    git clone https://github.com/watarika/ComfyUI-Text-Utility
    # restart ComfyUI afterwards
    

    No pip requirements, no model downloads - this node is pure Python string handling and doesn't even need Impact Pack (only the pack's wildcard nodes do).

    Categorytext

    Inputs (1)

    NameTypeDefaultDescription
    textSTRING

    Outputs (1)

    NameTypeDescription
    processedSTRING