ComfyUI Node

TagIf

Branch your prompt on whether certain tags are present

By sugarkwork·Created 2 years ago·Updated 6 months ago· 87
TagIf
    • output1
    • output2
    • output3
    • else_output1
    • else_output2
    • else_output3
    • tagin
    tags
    find
    anytagtrue
    output1
    output2
    output3
    else_output1
    else_output2
    else_output3

    TagIf is the pack's branch statement. You give it a tag string (say, WD14 Tagger output), a list of tags to look for, and two sets of outputs - one used when a match is found, one when it isn't. The classic use from the README: a tagged image that contains certain content routes to one positive/negative prompt pair, and anything else gets a different pair. It's prompt-level if/else without writing any Python.

    If you've fought with ComfyUI's lack of conditional logic before, this is the cheap version of what Impact Pack's conditionals do, scoped to exactly one problem: "do these tags appear?"

    How it works

    The tags input and the find input are both parsed the same way the rest of the pack parses tags - normalized to lowercase underscores, (tag:1.2) emphasis stripped for matching but remembered. So find: cat_ears matches (cat_ears:1.1) in your tags.

    The anytag toggle decides what counts as a hit:

    • True (default) - any one tag from find being present is enough.
    • False - all tags in find must be present. Useful for compound conditions like "has cat ears AND tail."

    If the condition is true, output1, output2, output3 flow through and the three else_output* ports return empty strings. If false, it's the mirror image: else outputs flow, main outputs are empty. A tagin BOOLEAN output also tells you the raw result, which is handy for driving a boolean gate or a UI display node.

    The output pattern that catches people

    The six string outputs are always live - they just return "" on the side that didn't win. So don't wire both sides into a text encoder and expect an empty string to be ignored; feed the two branches into a string combine or just pick the side you want. If all you need is the yes/no, read tagin and ignore the strings entirely.

    Also worth knowing: output1 is a required input, not optional like the others - the node won't even render until you've typed something in it, even if you only care about tagin. Set it to a placeholder if you're building a pure boolean gate.

    Where it slots in

    The natural chain in this pack: TagFilter or TagSelector trims a tagger's output down to the category you care about, TagIf reads whether a specific tag survived, and its tagin feeds something like TagSwitcher or a boolean router. A common one: "if the image contains animal_ears, suppress them in the prompt; otherwise leave it alone." That's exactly what this node was written for.

    Install

    Identical to the rest of the pack - ComfyUI Manager search "comfyui_tag_filter", or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/sugarkwork/comfyui_tag_fillter
    

    Restart and it's under the string category. No dependencies, no models. The only real gotcha is pack-wide: matching is only as good as the tag normalization, so whitespace between words in find is treated as an underscore - type long_hair, not long hair.

    Categorystring

    Inputs (9)

    NameTypeDefaultDescription
    tagsSTRING
    findSTRING
    anytagBOOLEANtrue
    output1STRING
    output2optSTRING
    output3optSTRING
    else_output1optSTRING
    else_output2optSTRING
    else_output3optSTRING

    Outputs (7)

    NameTypeDescription
    output1STRING
    output2STRING
    output3STRING
    else_output1STRING
    else_output2STRING
    else_output3STRING
    taginBOOLEAN