🟢Mask → Dict🗂️
The Mask That Rides Along
- dict
- value
- dict
Masks are the quiet glue of inpainting and compositing workflows: the region you want to regenerate, the subject you want to keep, the area you want to composite into. DictAddMask stores one in your dict under a named key, so the mask travels with the rest of the pipeline state instead of getting its own set of wires.
It's a standard media-type Add node: the MASK value is a wired input from whatever produced it - a segmenter, a hand-drawn mask, an image-to-mask conversion - and it's validated before being stored. Useful any time you have a mask that needs to reach a sampler or a composite step that isn't right next to it in the graph.
How it works
Dict Tools engine, same as every Add node: validate the MASK value, store under the key, return a new frozendict (never a mutation of your input), and sort keys alphabetically on each update. Chaining is safe, so you can drop image, mask, and latent into the same dict in three connected nodes.
The pattern that pays off: keep your inpaint mask in the dict alongside the image it applies to and the settings for the inpaint pass. One bus wire carries the whole job to the stage that needs it, and DictExtractMask pulls the mask back out exactly where it's needed.
The inputs that matter
- key (STRING) - the name you'll fetch the mask back by.
- cleanup_key (BOOL, default on) - trims stray spaces/newlines from the key.
- dict (DICT, optional) - an existing dict to extend, or empty to start one.
- value (MASK, optional) - the wired mask tensor.
Output is dict (DICT).
Install
ComfyUI Manager: search Dict Tools, install, restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/Lex-DRL/ComfyUI-DictTools
Restart after. Only dependency is frozendict, auto-installed by Manager.
Gotchas
Pack-wide: requires ComfyUI 0.18.0+ (newer node API). Failed to load → update ComfyUI.
The classic miss here is wiring an IMAGE where a MASK belongs - a lot of segmentation nodes output an image you then convert to a mask, and it's easy to skip that conversion step. The type check will catch it, but it'll cost you a run. Also, a mask extracted from the dict is a snapshot: if you grow or shrink the mask later in the workflow, re-add it to the dict or the bus is carrying stale geometry.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| key | STRING | Key (name) of the item inserted into the dict. | |
| cleanup_key | BOOLEAN | true | Automatically remove leading/trailing spaces and extra newlines from the key. |
| dictopt | DICT | An (optional) Dictionary to work with. | |
| valueopt | MASK | The actual Mask-type item to add into the Dict. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| dict | DICT | — |