ComfyUI Node

exclude keys

Cut keys out of a dict without touching the original

By StableLlama·Created about a year ago·Updated 4 days ago· 48
exclude keys
  • input_dict
  • keys_to_exclude
  • DICT

"exclude keys" takes a dictionary and a list of keys, and returns a new dictionary with those keys removed. It's the inverse of filter by keys (which keeps only what you name; this drops only what you name). You'd reach for it when a dict is carrying entries you don't want to pass on - a metadata blob full of internal fields, a settings dict with keys that would confuse a downstream node, or sensitive values you don't want sent to a log or API payload.

The word that matters in that first sentence is new. This node is non-destructive: the input dict is left untouched and you get a fresh dict back. In ComfyUI, where one node's output often feeds several others, that's not a nicety - it's the difference between "filtered dict for the save node" and "whoops, every downstream consumer now sees the filtered version too."

How it works

Two required inputs:

  • input_dict (DICT) - the dictionary to filter.
  • keys_to_exclude (LIST) - the keys to drop.

The implementation is thoughtful about the way Python dicts work: if there are few keys to exclude, it copies the dict and pops them one by one; if there are many, it rebuilds by comprehension. Either way it deduplicates the exclude list first. If nothing actually changed, it returns the original object; otherwise a new dict.

Inputs and outputs

  • input_dict (DICT)
  • keys_to_exclude (LIST)
  • Output: DICT - the filtered copy.

Gotchas

  • Keys that aren't in the dict are ignored. Excluding "nope" from a dict that never had it is a silent no-op, not an error.
  • keys_to_exclude takes a LIST, not a comma-separated string. Feed it a LIST from create LIST or a splitter; trying to type "a, b, c" into a string port won't connect.
  • Empty dict or empty exclude list: the node short-circuits and returns the input as-is.

When it's the right tool

Cleaning metadata before export is the classic use - strip generator-internal keys, keep the fields a consumer actually understands. It also composes beautifully with filter by keys: keep a whitelist or drop a blacklist depending on which list is easier to maintain. If your list of keys is more "these few must go" than "these few must stay," exclude is the one you want; for everything else, filter by keys is usually cleaner because a typo in a keep-list just means a smaller dict, whereas a typo in an exclude-list means a leaked entry.

Install

Ships in Basic data handling - pure Python, zero dependencies, no model downloads. ComfyUI Manager → search "Basic data handling", or:

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

then restart ComfyUI.

CategoryBasic/DICT

Inputs (2)

NameTypeDefaultDescription
input_dictDICT
keys_to_excludeLIST

Outputs (1)

NameTypeDescription
DICTDICT