ComfyUI Node

Conditional String

An if/else for text — the prompt-switch you'll forget to install until you need it

By DebugPadawan·Created about a year ago·Updated 5 months ago· 2
Conditional String
    • result
    condition
    true_stringTrue
    false_stringFalse

    Half of ComfyUI's awkwardness is that the graph has no if statement. You want "use prompt A when the seed is even, prompt B when it's odd," and suddenly you're staring at switch nodes and routers and wondering why this is hard. Conditional String is the unglamorous answer: one boolean in, one of two strings out. That's the entire job, and it does it without ceremony.

    It comes from DebugPadawan's ComfyUI Essentials, a small MIT-licensed grab-bag of logic, math, list, and conversion nodes. Nothing here generates images; it exists to make the graph decide things. This is the node that turns a comparison or a boolean test into text your prompt can use.

    How it works

    There's no mechanism to admire - it's a ternary: true_string if condition else false_string. Both strings are just strings; nothing gets evaluated or interpolated, so you can put arbitrary text on either side without worrying about side effects. The interesting part is upstream: what feeds the boolean.

    A typical chain: compare two numbers (the pack's Number Compare or a Logic Gate), get a BOOLEAN, and hand it to this node. True branch gets one prompt, false branch gets another. That's your dynamic prompt, done.

    The inputs that matter

    • condition - a real BOOLEAN. This is the gotcha: you can't feed it the string "true". If your condition is text, run it through a string-to-boolean converter (this pack has one) first.
    • true_string / false_string - both multiline STRING inputs, so multi-line prompts are fine. Defaults are literally True and False, which is handy for quick tests.

    The single output, result, is a STRING. Wire it anywhere a prompt or text input goes - CLIP Text Encode, a text templating node, a filename builder.

    Install

    Standard custom-node fare:

    cd ComfyUI/custom_nodes
    git clone https://github.com/DebugPadawan/DebugPadawans-ComfyUI-Essentials.git
    

    Restart ComfyUI afterward, or install via ComfyUI Manager by searching "DebugPadawan". requirements.txt lists numpy, torch, and opencv-python - both numpy and torch already ship with ComfyUI, and the shipped code never imports cv2, so there's nothing heavy to pull down and no model files. No API keys.

    Troubleshooting

    The usual failure is upstream: a string that looks boolean. Check that whatever feeds condition is genuinely a BOOLEAN output, not a text node that happens to spell "true". And remember the output is just text - if you're using it to branch a whole pipeline rather than pick a string, you actually want a switch/router node, not this. This node picks words; other nodes pick execution paths.

    CategoryDebugPadawan/Logic

    Inputs (3)

    NameTypeDefaultDescription
    conditionBOOLEAN
    true_stringSTRINGTrue
    false_stringSTRINGFalse

    Outputs (1)

    NameTypeDescription
    resultSTRING