ComfyUI Node

remove

Remove a key from a dict without ever seeing a KeyError

By StableLlama·Created about a year ago·Updated about 15 hours ago· 48
remove
  • input_dict
  • dict
  • key_removed
key

There are two ways to take a key out of a dict in Python: del dict["key"] (which explodes with a KeyError if the key isn't there) and dict.pop("key", None) (which doesn't). remove (Basic data handling: DictRemove) is the second kind, and it's the one you want in a workflow graph, because graphs don't handle "explodes" gracefully.

It takes two required inputs:

  • input_dict - the DICT you're removing from
  • key - the key to remove, as a STRING

and returns two outputs:

  • dict - a new dictionary with the key gone
  • key_removed - BOOLEAN, True if the key was actually found and removed

The mechanism is refreshingly boring: key not in input_dict returns the dict untouched with key_removed = False; otherwise it copies the dict, deletes the key, and reports True. No exceptions, ever. That means you can wire a key into this node from anywhere - a prompt, a parsed config, a filename - and never worry about a missing-key edge case taking down the whole queue.

Why this beats a raw delete

Two things to like. First, the key_removed output is a free existence check. Feed it into a comparison or this pack's if/else and you can react to "did that key even exist?" without a separate DictContainsKey node. Second, it doesn't mutate your source dict - the node works on a copy - so the dict that flowed in is still valid for anything else wired to it. In a graph where data can be consumed by multiple branches, non-destructive edits are a quiet lifesaver.

If you need to remove something and get its value back, that's what this pack's pop node is for. remove just takes it out and tells you whether it was there.

Installing it

This node lives in the Basic data handling pack by StableLlama. Through ComfyUI Manager, search "Basic data handling", install, restart. Or manually:

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

then restart ComfyUI. No dependencies, no requirements.txt, no model files - just Python.

Troubleshooting

The one thing that trips people up here is the same thing that trips them up across this pack: DICT is a custom data type, not a ComfyUI native one. The input_dict socket only accepts DICT outputs - which in practice come from other nodes in this pack (like DictCreate). If you can't plug something in, it's because you're feeding it a type this pack doesn't recognize, not because the node is broken. Also worth knowing: the key comparison is exact string matching, so "prompt" and "Prompt" are different keys.

CategoryBasic/DICT

Inputs (2)

NameTypeDefaultDescription
input_dictDICT
keySTRING

Outputs (2)

NameTypeDescription
dictDICT
key_removedBOOLEAN