ComfyUI Node

_.pick

Whitelist a Dictionary Down to the Keys You Care About

By sfinktah·Created about a year ago·Updated 10 months ago· 7
_.pick
  • py_dict
  • keys
  • DICT

_.pick is the "keep only these keys" node. You hand it a dict and an allowlist of keys, and it returns a copy of the dict containing just those entries. It's the whitelist twin of _.omit, and it's one of the handiest tools in the underscore family for taming metadata.

When you'd reach for it

Real workflow data is bloated. Image-info payloads, metadata extractors and VHS-style nodes hand you dicts with way more keys than you'll ever use. _.pick is how you cut a dict down to exactly the fields you want - say, extracting {"seed", "cfg", "steps"} from a giant generation-metadata blob before you pass it to a formatter or a saver. It's also the safe way to build a clean config object from a messy source: pick the keys you trust, and everything else is silently dropped.

The inputs:

  • py_dict - the dictionary to filter
  • keys - a single key, or a JSON array of keys like ["seed", "cfg"]

Output: a DICT with only the allowed keys.

How it works

It builds a fresh dict, copying over only the entries whose keys are in your allowlist. Keys you named that don't exist in the source are simply skipped - no error, no placeholder. The source dict is deep-copied first, so nothing upstream is mutated, and you can safely wire the same dict into a pick and an omit branch at the same time.

The one habit to build: keys parses JSON. For multiple keys, pass a JSON array - ["a", "b"] - not "a, b". A single key works as plain text, but arrays are where people get tripped up. The pack's String Format node can build that array dynamically if your field list is computed.

Pick vs. omit

Same job, opposite direction. _.pick keeps only what you name - right when you know exactly which fields you want. _.omit keeps everything except what you name - right when you know what you don't want. For a metadata blob where you want three of twenty fields, pick is the obvious choice and the one I'd reach for.

Installing

Part of comfy-ovum. ComfyUI Manager → search comfy-ovum → Install, or:

cd ComfyUI/custom_nodes
git clone https://github.com/sfinktah/comfy-ovum

Restart ComfyUI. No models, no extra pip packages for the underscore nodes - the underscore.js port is bundled in the repo.

The bottom line

The clean way to pull a handful of fields out of a fat dict. Keep the JSON-array habit for multiple keys and you're set.

Categoryovum/underscore

Inputs (2)

NameTypeDefaultDescription
py_dictopt*Primary input object (expected object). You can still pass any JSON-serializable value. Also accepts _.CHAIN to continue chaining.
keysopt*keys: JSON allowed for arrays/objects where applicable.

Outputs (1)

NameTypeDescription
DICTDICT