Nodes/ComfyUi-MpiNodes/Mpi Block If Empty List
ComfyUI Node

Mpi Block If Empty List

Stop an IndexError before it happens, with the whole list in view

By MadPonyInteractive·Created 11 months ago·Updated 5 days ago· 3
Mpi Block If Empty List
  • list_input
  • list_output

The failure mode this node exists for is one of the most common in ComfyUI: you build a workflow around a list - a batch of images, a set of prompts, a pile of latents - and some runs, that list comes back with zero items. The next node indexes into it, hits IndexError, and the whole thing dies with a traceback that gives you no idea which node betrayed you. Mpi Block If Empty List is the tripwire that makes an empty list halt the branch quietly instead.

The mechanism is the interesting part, because it's deliberately different from Mpi Any Blocker. This node declares INPUT_IS_LIST = True, which means it receives the entire list as one value and its doit runs once on the whole thing. That one detail is why it works at all: ComfyUI's list handling is per-item by default, so a node wired to a list input actually executes once per element - and with zero elements, it never executes at all. A plain blocker would be skipped by an empty list, never running, never blocking anything. Because BlockIfEmptyList consumes the full list in one go, an empty [] does reach it, it sees len(list_input) == 0, and it returns a list of ExecutionBlockers - ComfyUI reads that as "everything downstream of this node produces nothing" and skips the branch.

Inputs and outputs are as thin as they get: list_input in (wildcard *, any list type) and list_output out, the same list passed through when it has items. You drop it on the wire before whatever indexes into the list - a "get image at index" node, a list range, a node that takes the first element. When the list is healthy, it's a transparent pass-through. When it's not, the branch silently doesn't run instead of crashing.

Where this fits in a real graph: think of the "build a batch, then process it" pattern. Upstream you've got a node that can legitimately return an empty batch - a folder loader with no matching files, a filter that kept nothing, a prompt list that produced zero selected options. Downstream you've got per-item processing that assumes at least one thing exists. The list blocker between them converts "sometimes an empty batch, and a crash" into "an empty batch is a completed no-op." It's the list-aware sibling of the blocker family in this pack, and it pairs with MpiListCount / MpiIsListEmpty when you need the count or a flag rather than a hard stop.

The honest caveat: it only guards the branch after it. Everything feeding the node still runs, because the list has to be built before it can be checked. If your expensive upstream work is the thing you want to skip when the result would be empty, that's a problem for lazy-evaluated gating (Mpi Blocker), not this node. And if your value isn't a list at all - a single string, a lone tensor - you want Mpi Any Blocker instead, since this one is explicitly list-shaped.

Install is the pack standard and takes a minute: ComfyUI Manager → search ComfyUi-MpiNodes → install → restart. Or the manual route:

cd ComfyUI/custom_nodes
git clone https://github.com/MadPonyInteractive/ComfyUi-MpiNodes

Restart, and the node appears under MpiNodes/Logic. No extra dependencies, no model downloads - this pack is pure Python plumbing on top of what ComfyUI already ships, which is why the logic nodes install in seconds.

CategoryMpiNodes/Logic

Inputs (1)

NameTypeDefaultDescription
list_input*

Outputs (1)

NameTypeDescription
list_output*