ComfyUI Node

format_map

Prompt templates without string gymnastics

By StableLlama·Created about a year ago·Updated about 16 hours ago· 48
format_map
  • mapping
  • STRING
templateHello, {key}

You want to build text from a template - "a {subject} in the style of {style}, {quality}" - and fill in the blanks from values. That's exactly what this node does, and it's quietly one of the most useful things in the pack. It's how you make dynamic prompts without a snake pit of concat nodes.

What it does

format_map is Python's str.format_map() exposed as a node. Your template contains placeholders in curly braces - {name}, {style} - and a mapping (a DICT) supplies the values. Every placeholder is replaced by the corresponding value, converted to string. "Hello, {name}" with {"name": "World"} produces "Hello, World".

The inputs that matter:

  • template - the string with placeholders, default "Hello, {key}" (required).
  • mapping - a DICT holding the key/value pairs (required).

Output: one STRING.

The catch: missing keys don't crash

This is the behavior to know. If the template references a key that isn't in the mapping, the node doesn't throw - it returns a string like "Key error: 'x' not found in mapping" as its output. That error text then flows downstream like any normal string, into your prompt or filename, looking like garbage rather than failing loudly. It's friendly, but it means you should validate that your mapping actually contains every key your template uses. A typo in one placeholder and the failure is silent.

Why you'd reach for it

Any templated text. Dynamic prompts assembled from parts you compute in the graph - subject from one node, style from another, quality from a third. Filename templates like "{name}_{date}" before the path nodes write them. It's the readable alternative to chained concats, and worth it the moment you're assembling more than two pieces.

The mapping is a real DICT, so you build it with the pack's DICT nodes - create, set, or create from items. That's the one setup step people miss: the template input is a plain string, but the values have to arrive as a dict.

Installing

Part of Basic data handling by StableLlama. In ComfyUI Manager search "Basic data handling" → Install → restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling

Restart. Zero runtime dependencies - pure stdlib - so nothing extra to install and no dependency conflicts.

Where people get burned

The missing-key behavior is the big one - silent error strings in the output. Next is forgetting the DICT: you can't just type values in, the mapping input has to be wired from a dict-producing node. And the syntax is {key}, not %s or ${key} - people coming from other templating habits get tripped up on that.

CategoryBasic/STRING

Inputs (2)

NameTypeDefaultDescription
templateSTRINGHello, {key}
mappingDICT[object Object]

Outputs (1)

NameTypeDescription
STRINGSTRING