Nodes/ComfyUI-YogurtNodes/DictFilter (Yogurt Nodes)
ComfyUI Node

DictFilter (Yogurt Nodes)

Slice a dict down to the entries you actually care about

By yogurt7771·Created 2 years ago·Updated 9 days ago· 1
DictFilter (Yogurt Nodes)
  • dict_data
  • filtered_dict
pattern.*
filter_bykey
invertfalse

DictFilter is the pack's answer to "this dict has 40 keys and I need the 6 that matter." You hand it a dict and a regex pattern, tell it whether to match against keys, values, or both, and it returns a new dict containing only the entries that matched. It's filtering as a first-class node, which is a surprisingly welcome thing once you're dealing with big metadata blobs or API responses.

The power is in the regex. The default pattern is .* - matches everything, so a bare node is a no-op copy. Change it to something like ^lora_ and you keep only the entries whose keys start with lora_; use quality|scale and you grab the entries that mention either term. Because it uses re.search (not full-string match), a pattern like _model$ catches keys ending in _model, and fps catches anything containing "fps." If you're pulling from an LLM or an API where the schema drifts, this is how you defensively whittle a dict down to a known subset before handing it to typed nodes.

The filter_by and invert dials add real nuance:

  • key (default) - match against keys only.
  • value - match against values only.
  • both - keep an entry if either its key or its value matches.
  • invert - flip the result, keeping everything that did not match.

The invert toggle is where this gets more useful than a hand-rolled filter: "give me everything that isn't a _debug key" is one checkbox instead of a nasty regex.

How it works

Under the hood it compiles your pattern and does a regex search over the chosen side(s), converting values to strings for the match (so numbers are matched as their string form). The XOR in the logic means matches != invert decides what's kept - clean, predictable behavior you can reason about.

Inputs

  • dict_data - the dictionary to filter.
  • pattern - regex to match against, default .*.
  • filter_by - key, value, or both.
  • invert - keep non-matches instead.

Output

  • filtered_dict - a new dict with only the kept entries. Your input is untouched.

Install

Part of ComfyUI-YogurtNodes:

cd ComfyUI/custom_nodes
git clone https://github.com/yogurt7771/ComfyUI-YogurtNodes.git
cd ComfyUI-YogurtNodes
pip install -r requirements.txt

Or search "YogurtNodes" in ComfyUI Manager and restart. Under "Yogurt Nodes" → Logic.

Common issues

  • "It filtered out everything" - your regex doesn't match what you think. Test it mentally: re.search("foo", "foobar") succeeds, but re.search("^foo$", "foobar") fails. Anchors are literal.
  • "Values that are numbers won't match" - they're stringified for matching, so 123 matches the pattern ^12. Watch for partial matches.
  • "Pattern too clever" - remember this is a standard Python regex; anything you'd use in a Regex Node here works the same.

Pair it with DictKeys and DictLength to verify what survived the cut. For the "keep the good stuff, drop the noise" work in a data-heavy workflow, this is the node.

CategoryYogurtNodes/Logic

Inputs (4)

NameTypeDefaultDescription
dict_data*Dictionary to filter
patternSTRING.*Regex pattern to match
filter_byoptCOMBOkeyWhat to filter by: key, value, or both
invertoptBOOLEANfalseInvert the filter (exclude matches)

Outputs (1)

NameTypeDescription
filtered_dict*