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

DictGet (Yogurt Nodes)

Pull a value out of any dict without the KeyError ambush

By yogurt7771·Created 2 years ago·Updated 9 days ago· 1
DictGet (Yogurt Nodes)
  • dict_data
  • default_value
  • value
key
use_defaultfalse

DictGet is the workhorse of the pack's dict family: you hand it a dictionary and a key, it hands you the value. In a language with dicts as a first-class citizen, this is the dict["key"] access you do a hundred times a day - and in ComfyUI, where dicts show up as the output of JSON nodes, metadata parsers, or LLM responses, being able to reach in and pull one field out is what turns a blob of structured data into something you can actually use.

The twist that makes this node worth a look instead of just using a raw indexer is the use_default flag. A plain dict[key] raises KeyError and kills the whole graph if the key isn't there. With use_default flipped on, it becomes dict.get(key, default_value): missing key, wrong type, whatever - you get your fallback and the workflow keeps rolling. When you're parsing LLM output or API responses whose exact fields you can't guarantee, that graceful-degradation behavior is the difference between a pipeline that survives and one that explodes on the first weird response.

How it works

Straight Python underneath. If use_default is on, it calls dict.get(key, default_value); if off, it does dict_data[key] and lets a missing key raise. The default_value input is *-typed, so your fallback can be a string, a number, a list, anything - which makes it easy to feed a sentinel value downstream that your logic nodes can catch.

Inputs

  • dict_data - any dict-like object that supports string indexing.
  • key - the key to look up, as a string.
  • default_value - what to return when the key is missing (only used if use_default is on).
  • use_default - the switch between "safe .get()" and "raise on missing."

Output

  • value - *-typed, so whatever you pulled can flow into any matching port.

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. It's under "Yogurt Nodes" → Logic, alongside the rest of the dict family.

Common issues

  • "It crashed with KeyError" - use_default is off. That's by design: it's the strict mode that surfaces mistakes. Flip it on if you want resilience instead.
  • "I got the default but I expected a value" - the key genuinely isn't there, or the dict isn't what you think it is. Pipe the dict through YogurtDictKeys first to see what keys actually exist.
  • "The key is a number, not a string" - keys are typed as STRING here; if your dict uses integer keys you'll need to stringify or use a different access path.

If you're doing a lot of field extraction from JSON, pair it with the pack's JsonGetPath for path-based access. DictGet is the right tool when you already know the exact key and just want a value out - safely, if you ask it nicely.

CategoryYogurtNodes/Logic

Inputs (4)

NameTypeDefaultDescription
dict_data*Any dict-like object that supports string indexing
keySTRINGKey to access
default_valueopt*Default value to return if key not found (uses dict.get())
use_defaultoptBOOLEANfalseUse default value instead of raising KeyError

Outputs (1)

NameTypeDescription
value*