ComfyUI Node

filter empty

Filter empty for Data Lists

By StableLlama·Created about a year ago·Updated 8 days ago· 52
filter empty
  • list
  • list
◄treat_whitespace_as_emptyfalse►

You split a prompt file into lines, wire it into a batch, kick off a queue of forty images, and come back to find that four of them are mush. Nothing crashed. The prompt was just empty, because your text file ended with a newline, or because someone left a double ,, in the middle of a variant list, and ComfyUI cheerfully ran the whole graph on a blank string. That's the exact hole this node plugs.

It's a one-job utility: strip the empties, keep the order.

What "Data List" actually means here

ComfyUI has three collection types and this node only works properly on one of them. A data list is ComfyUI's native list type - the one where each item is processed individually, so the graph downstream of this socket runs once per entry. That's the whole reason blank entries are expensive rather than merely untidy: an empty entry isn't skipped, it's a queue item. The other two types, LIST and SET, are plain Python containers passed along as a single value; the plumbing map in our knowledge base covers the distinction and it's the single most common thing to get wrong in this corner of the graph.

Where do data lists come from? Splitting text (the pack has data-list variants of split/splitlines under Basic/STRING), reading lines out of a prompt file, and wildcard pickers like Impact Pack's - the pack that, per our panel on it, quietly owns wildcards for a large share of the ecosystem. Wildcard files are hand-edited text files, and hand-edited text files contain blank lines.

How it works

Under the hood it's a list comprehension and nothing else - the whole pack is pure Python with dependencies = [] in its pyproject.toml, so there's nothing to compile, no wheels, no models. The emptiness test is the interesting part, because it is not Python truthiness:

  • None is empty.
  • An empty string "" is empty. So is " ", but only if you ask for that.
  • Anything with a length of zero - [], {}, set() - is empty.
  • 0 and False are kept. Numbers and booleans are never empty. That's deliberate, and it's why you can't just swap in a generic filter node and get the same behaviour.

The two fields you touch

list is the required input: the Data List to clean. Wire it in wherever your list was already going.

treat_whitespace_as_empty is the optional boolean, off by default, and it's the one that decides whether this node earns its place. With it off, a string of spaces or tabs survives, which is exactly what you get when you split "a, , b" on commas or read a file with Windows line endings. Flip it on and whitespace-only strings count as empty too. It only ever applies to strings - the author's own tooltip says as much - so a 0-dimensional tensor or a bare number is unaffected either way.

The single output, list, is a new Data List. Same wiring as before: prompt encoders, save nodes, whatever consumed the list. The difference is that the downstream branch now runs fewer times, which is the entire point.

Installing it

It's in ComfyUI Manager under the pack title Basic data handling - install from there and restart. Manually:

cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
# restart ComfyUI

It shows up under Basic/Data List as filter empty.

Where people get burned

You upgraded nothing, so the node isn't there. This node is new in pack version 2.2.0, and the pack's changelog is blunt about it - "Data List and LIST: new filter empty node." If Manager shows you something older, or you cloned a while back, you won't have it. Update the pack first before concluding the search box is broken.

You wired the wrong twin. There are two nodes with the identical display name filter empty. The one in this article takes a data list (input type *, and it's a list that fans out per item); its twin in Basic/LIST takes a LIST. If you feed a LIST into this one, ComfyUI has no way to hand a node that runs per item a single collection - it wraps the whole thing into a one-item list - so nothing gets filtered and the node looks broken. Check the category label in the node title bar.

You filtered everything. If every entry was blank, the output has zero items and the downstream branch runs zero times. ComfyUI won't warn you; you just get no images and a suspicion that the sampler died. Put a length node on the list while you're debugging.

You expected 0 and False to disappear. They don't, by design. If your data mixes legitimate zeros with blank cells and you wanted both gone, this node only handles half the problem.

CategoryBasic/Data List

Inputs (2)

NameTypeDefaultDescription
list*The Data List whose empty entries are removed.
treat_whitespace_as_emptyoptBOOLEANfalseWhen enabled, STRINGs that consist only of whitespace (spaces, tabs, line breaks) are removed as well.

Outputs (1)

NameTypeDescription
list*A new Data List without the empty entries.