ComfyUI Node

TagEmpty

Swap in a fallback prompt when your tags come back empty

By sugarkwork·Created 2 years ago·Updated 6 months ago· 89
TagEmpty
    • tags
    • empty
    tags
    alt_tags

    TagEmpty is the pack's safety net. Feed it a tag string and an alternative, and it answers the question every batch job eventually asks: "what do I do when the tagger produced nothing?" If tags parses to an empty list, the node returns alt_tags instead and sets empty to True. If there's real content, it passes the tags through untouched with empty set to False.

    The "parses to empty" phrasing matters, because this isn't a dumb if string == "" check - it runs the input through the pack's tag parser. A string of pure whitespace, a string of commas with nothing between them, or (( )) with no actual tag all count as empty. Meanwhile a legitimately short string like smile counts as full. It's a semantic emptiness check, not a character count, which is the right behavior for downstream prompt use.

    The two outputs

    • tags (STRING) - your input tags, or alt_tags if the input was empty.
    • empty (BOOLEAN) - the raw emptiness verdict, available even if you don't care about the fallback. That boolean is the real gift: it's a clean "did we get anything?" signal you can route into a condition node or a display.

    Where it saves you

    The classic failure this fixes: a WD14 tagger that failed to tag an image, a batch input with a blank line, or a node upstream that returned "" instead of a prompt. Without a fallback, that empty string flows into your text encoder and you generate whatever a prompt-less model dreams up - usually garbage, and you won't notice until you've burned a whole batch. With TagEmpty in the chain, empty input becomes a deliberate, controlled prompt instead.

    The natural partner in this pack is TagDetector: detect tags from messy text, then TagEmpty catches the case where detection found nothing and substitutes a known-good prompt. It also composes with TagFlag or TagIf for "if no tags, skip this branch entirely" logic via the empty boolean.

    Gotchas

    The fallback only fires on empty, not on "one weird tag." If the tagger emitted a single junk token, TagEmpty treats it as content and passes it through. And there's no trimming - if you want the output normalized, run it through TagMerger or similar afterward. Small node, small job, and it does it correctly.

    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, done. No dependencies, no model downloads - the whole node is a dozen lines of Python. For the cost of one node in the graph you stop generating from empty prompts, which is one of the cheaper quality wins available in a batch workflow.

    Categorytext

    Inputs (2)

    NameTypeDefaultDescription
    tagsSTRING
    alt_tagsSTRING

    Outputs (2)

    NameTypeDescription
    tagsSTRING
    emptyBOOLEAN