ComfyUI Node

Switch String

Swap prompts on a condition, not by hand

By danipisca07·Created 6 months ago·Updated 6 months ago· 0
Switch String
    • STRING
    conditionfalse
    if_true
    if_false

    Switch String takes a boolean condition and two strings, if_true and if_false, and returns one of them. On paper that's the least exciting sentence in this pack. In practice it's the node that stops you from manually swapping prompts and filenames between every run, and it's a big reason conditional workflows feel like actual programs.

    Why you'd reach for it

    The classic use is prompt swapping. You want two moods of the same scene - a daytime variant and a nighttime variant, a clean version and a stylized one - and a single checkbox picks which string feeds the CLIP Text Encode. Before the switch, that meant editing a text box every time you queued. After, it's one boolean you flip, or better yet, a boolean that a comparison computes for you.

    It's just as useful for the non-prompt strings: filenames, wildcard paths, negative prompts, LoRA trigger-word blocks, metadata. "If this flag is set, save as final_v2; otherwise draft" is a Switch String plus a filename node away from automatic. And like the rest of the pack's logic, the condition can be a checkbox, a Compare result, or a gate like OR - so a workflow that compares two images can route to the "keep this one" label all by itself.

    How it works

    The implementation is the same if_true if condition else if_false you see across this pack's switch family, but with strict STRING sockets - the candidate values can't accidentally be numbers, which keeps your prompt wires honest. The author's description: "Returns if_true when condition is True, otherwise returns if_false. Works with strings." It sits in SimpleLogics/Switch with the int, float, and any-type variants.

    The inputs that matter

    Three required inputs:

    • condition - the BOOLEAN that picks the branch (defaults to False)
    • if_true - the STRING returned when condition is true (default "")
    • if_false - the STRING returned when condition is false (default "")

    One STRING output, ready for a text encode, filename builder, or any string socket.

    Installing it

    Comes with danipisca07/ComfyUI-SimpleLogics, the dependency-free pure-Python pack - no requirements.txt, no models. Install from ComfyUI Manager (search "SimpleLogics") or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/danipisca07/ComfyUI-SimpleLogics
    

    Restart ComfyUI and you're done.

    Common issues

    The usual failure is forgetting that a switch selects, it doesn't merge - if you were hoping for "put both strings together," you want a concatenation node, not this. The other trap is empty-string defaults: with the default "" on both sides, a switch you wired lazily can silently pass through an empty prompt and give you a model that ignores your intent. If output looks "unprompted," check whether your condition is actually connected or sitting on its False default. Beyond that it's a pure selector - nothing to break. (And the usual pack quirk: installing SimpleLogics also registers an undocumented GeoCalib camera node - ignore it.)

    CategorySimpleLogics/Switch

    Inputs (3)

    NameTypeDefaultDescription
    conditionBOOLEANfalse
    if_trueSTRING
    if_falseSTRING

    Outputs (1)

    NameTypeDescription
    STRINGSTRING