Nodes/ComfyUI-nhknodes/πŸ”€ Conditional Router (nhk)
ComfyUI Node

πŸ”€ Conditional Router (nhk)

The If/Else Your Workflow Never Had β€” Conditional Router (nhk)

By EnashkaΒ·Created 12 months agoΒ·Updated 28 days agoΒ· 23
πŸ”€ Conditional Router (nhk)
  • pass_input
  • fail_input
  • output
  • info
β—„conditiontrueβ–Ί

Conditional Router (nhk) is an if/else for your graph. It takes one boolean condition and two inputs, and routes whichever one matches: true sends pass_input to the output, false sends fail_input. Simple to state, surprisingly powerful once you realize it's lazy - the branch you don't pick never actually runs.

That laziness is the whole reason to use it. ComfyUI doesn't have native conditionals; normally every connected path executes, whether you want it to or not. So "if this image passes evaluation, upscale it; otherwise regenerate" requires you to actually gate which path runs. A lazy router does exactly that, and it's why this node sits in the pack's image-evaluation family: an AI evaluator outputs a pass/fail boolean, and this router picks the "pass" processing chain or the "fail" chain on the spot.

How it works

The mechanism is check_lazy_status, ComfyUI's lazy-evaluation hook. During graph planning, the node declares which of its inputs it will actually need - pass_input if the condition is true, fail_input if false - and ComfyUI only executes the chain feeding that input. The other chain is pruned. No wasted sampler runs, no unwanted side effects on a path you're not taking.

When executed, it returns your chosen input plus an info string recording which path won ("Using pass_input" / "Using fail_input"), which prints to the console too - handy for confirming the routing behaved.

Inputs and outputs

  • condition - boolean, default true. True = pass_input, false = fail_input.
  • pass_input - the input chain used when true (lazy).
  • fail_input - the input chain used when false (lazy).

Outputs:

  • output - the selected input, passed through.
  • info - a STRING saying which path was taken.

All inputs are wildcard (*), so you can route images, latents, conditioning, strings - anything.

Installing it

Part of ComfyUI-nhknodes:

cd ComfyUI/custom_nodes && git clone https://github.com/Enashka/ComfyUI-nhknodes

restart, or "NHK Nodes" from ComfyUI Manager. It loads under nhk/wip.

The honest caveats

First, it's WIP - the author flags this family as experimental while sorting out ComfyUI's pull-based execution quirks, so behavior may shift between versions. Second, the laziness cuts both ways: a node with side effects sitting on the unselected branch simply won't run, so don't rely on it firing. Third, the pull-based gotcha from the pack's own docs applies here too - ComfyUI executes backward from terminals, so if the branch feeding this router dead-ends without a real terminal, nothing upstream runs and the router may never fire. Build with a terminal at the end of each branch, test the false path once, and this becomes one of those "how did I do without it" nodes. If you need to route a pair of values together rather than one, the pack's Conditional Router Dual is the same idea with two lanes.

Categorynhk/wip

Inputs (3)

NameTypeDefaultDescription
conditionBOOLEANtrueTrue = use pass_input, False = use fail_input
pass_input*Input chain to use when condition is True
fail_input*Input chain to use when condition is False

Outputs (2)

NameTypeDescription
output*Selected input based on condition
infoSTRINGWhich path was taken