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

DictContainsKey (Yogurt Nodes)

Ask 'is this key there?' and get a boolean back

By yogurt7771·Created 2 years ago·Updated 9 days ago· 1
DictContainsKey (Yogurt Nodes)
  • dict_data
  • contains
key

DictContainsKey is the smallest member of the pack's dict family, and its whole job fits in one sentence: it tells you whether a dictionary contains a specific key, as a clean true/false output. If you've ever wanted to branch a workflow on "does this parsed JSON actually have the error field?" without crashing, this is the node.

Where it earns its keep is in defensive logic. Real-world data - an API response, an LLM's JSON output, a config blob - doesn't always have the fields you expect. Before you call DictGet on something, you often want to check it exists, then route the result into a Switch or conditional path: "if the dict has width and height, use them; otherwise fall back to defaults." Two booleans, one per check, and your graph politely handles both worlds. It's also the natural companion to DictGet's use_default flag - but instead of a fallback value, this gives you a fallback branch, which is sometimes what you actually want.

How it works

Under the hood it's Python's membership test, key in dict_data, which checks the dict's keys and ignores values entirely. There's no type confusion to worry about - you give it a string key, it checks it. One caveat: the key input is a STRING. If your dictionary uses non-string keys (integers, tuples), you can't type those directly here, so string-keyed dicts are the sweet spot - which covers the JSON/LLM-output case that dominates real usage.

Inputs & output

  • dict_data - any dict-like object.
  • key - the string key to search for.
  • contains - BOOLEAN output: true if the key is present, false otherwise.

Wire contains into any node that takes a boolean - a switch, a conditional, or just to make the state visible.

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.

Common issues

  • "It says false but I can see the key" - double-check the spelling and case; keys are matched exactly. Pipe the dict through YogurtDictKeys to see the actual key strings.
  • "I need to check a value, not a key" - that's YogurtDictContainsValue, the sibling node in the same pack.
  • "My keys aren't strings" - the key input is STRING-typed; stringify or restructure the dict upstream (a ToDict pass can help).

Tiny node, real utility. It's the "look before you leap" of dict access, and once you start building resilient workflows you'll find yourself dropping it in front of every DictGet.

CategoryYogurtNodes/Logic

Inputs (2)

NameTypeDefaultDescription
dict_data*Any dict-like object
keySTRINGKey to search for

Outputs (1)

NameTypeDescription
containsBOOLEAN