Switch (Optional)
An if/else for your graph that only runs the branch you pick
- on_false
- on_true
- output
IPT-OptionalSwitch is your graph's if/else: a boolean decides which of two inputs flows out. Sounds like every switch node you've ever seen, but there's one property here that most A/B switches don't have, and it's the whole reason this node exists: it only evaluates the branch you pick. Flip the switch to false and the entire upstream chain feeding on_false's opposite never runs - not just skipped, never executed. That's the difference between saving a few milliseconds and skipping a whole KSampler, detailer pass, or model load.
It comes from kinorax/ComfyUI-Info-Prompt-Toolkit, the image-info utility pack, and it's built for the "one workflow, many modes" problem: sometimes you want the upscale, sometimes you don't; sometimes you want the refiner, sometimes a plain pass-through. With a normal switch, both branches still execute and you waste the compute. With this one, the dead branch is free.
How it works
ComfyUI's execution engine supports lazy inputs: a node can declare which of its inputs should be evaluated only if they're actually needed. IPT-OptionalSwitch uses that - its check_lazy_status asks the engine to evaluate on_true only when the switch is true, and on_false only when it's false. So the heavy upstream node on the losing side is never run. The second trick: if the selected branch is unconnected, the node returns None instead of erroring. Leave on_false unwired and flip the switch off, and downstream just receives None - which, by ComfyUI's optional-input convention, downstream nodes read as "not connected." That turns this into a mute button: bypass a branch by leaving it empty rather than deleting it.
The inputs that matter
- switch - the boolean. This is the only required input. Could be a fixed toggle or driven by another node.
- on_true - the value passed through when switch is true. Optional.
- on_false - the value passed through when switch is false. Optional.
One output: output - the selected value, or None when the selected branch is unconnected. It's a wildcard (*) type, so it can carry an image, a latent, a string, a model - anything.
Installing it
Part of the IPT pack, installed once:
cd ComfyUI/custom_nodes
git clone https://github.com/kinorax/comfyui-info-prompt-toolkit.git
cd comfyui-info-prompt-toolkit
pip install -r requirements.txt
Restart ComfyUI (or install via ComfyUI Manager, searching "ComfyUI-Info-Prompt-Toolkit"). No models, no heavy deps.
Where people get burned
Don't confuse this with the fallback switches like rgthree's Any Switch, which walk their inputs and pass the first non-empty one with no selector. This is an explicit valve - you choose, the graph doesn't. The lazy evaluation is the killer feature, but it has a caveat: the lazy part saves execution, not loading. If the losing branch references a node class you don't have installed, the workflow still won't load; lazy evaluation can't rescue a missing node. And when both branches are unconnected, you get None out - make sure whatever's downstream can handle None, or you've just fed a KSampler a None latent and the error message will be confusing.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| switch | BOOLEAN | — | |
| on_falseopt | COMFY_MATCHTYPE_V3 | Value returned when switch is false. May be unconnected. | |
| on_trueopt | COMFY_MATCHTYPE_V3 | Value returned when switch is true. May be unconnected. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| output | COMFY_MATCHTYPE_V3 | Selected value, or None when the selected branch is unconnected. |