Nodes/Comfyui-General-API-Node/Text Logic Switch (FeiMao-326)
ComfyUI Node

Text Logic Switch (FeiMao-326)

Route on 'Error', check a pattern, branch your workflow

By FeiMao-326·Created 12 months ago·Updated 5 months ago· 0
Text Logic Switch (FeiMao-326)
    • result
    text
    pattern
    modecontains
    on_trueTrue
    on_falseFalse

    ComfyUI is a dataflow graph, and dataflow graphs are famously bad at "if this, do that." Core ComfyUI has no native conditional - you end up stacking bypass nodes or accepting that every branch runs every time. This node is a text-based conditional: check some incoming text against a pattern, and output one string on a match, another on no match. Two strings out, and you've built a branch.

    How it works

    Inputs: text (what you're testing), pattern (what you're looking for), mode (how to compare), and on_true / on_false (the strings to output). The six modes:

    • contains - pattern is a substring. The default, and the workhorse.
    • not_contains - the inverse.
    • regex - pattern is treated as a regex; re.search, so it matches anywhere.
    • exactly - text equals pattern, whole string.
    • starts_with / ends_with - prefix and suffix checks.

    The output is one STRING named result: on_true when the check passes, on_false when it doesn't. That's the whole mechanism, and it's refreshingly free of hidden behavior - no partial matching, no case-folding unless your regex does it.

    Where it fits

    The author's example is the good one: check if an LLM's output contains "Error" and, if so, stop the workflow or route to a fallback model. That's a genuinely useful pattern now that LLM nodes are common - one wrong API call can poison the rest of the graph, and a text switch is the cheapest guard. You connect the General API Node's describe output here, set pattern to Error, on_true to something that halts, on_false to the actual text, and you've built a poor man's try/catch.

    Other natural uses: gate a branch on whether a prompt contains a keyword, decide between two templates, validate that a parsed value came back non-empty. Because on_true and on_false are arbitrary strings (multiline), they can carry whole prompts, not just True/False - which is the difference between "a switch" and "a text router."

    Two caveats worth knowing. First, it outputs a string, not a connection that physically disables a branch - whatever is downstream of the chosen string still runs, but with your chosen content. If you need to actually skip work, wire the on_false output into a bypass-style node instead. Second, regex mode swallows invalid patterns silently (returns false rather than erroring), so a typo just makes the branch never fire - worth checking if your branch "mysteriously" always goes false.

    Inputs and outputs

    • text (STRING, multiline) - the text to test.
    • pattern (STRING) - what to look for.
    • mode (enum) - contains / not_contains / regex / exactly / starts_with / ends_with.
    • on_true / on_false (STRING, multiline) - the two outputs.
    • result (STRING) - whichever branch matched.

    Installing

    It ships in the FeiMao-326 pack. ComfyUI Manager (search "Comfyui-General-API-Node") or:

    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 → Text Logic Switch. Light dependencies, no model downloads.

    CategoryFeiMao-326

    Inputs (5)

    NameTypeDefaultDescription
    textSTRING
    patternSTRING
    modeCOMBOcontains6 options: contains, not_contains, regex, exactly, starts_with, ends_with
    on_trueSTRINGTrue
    on_falseSTRINGFalse

    Outputs (1)

    NameTypeDescription
    resultSTRING