ComfyUI Node

String Format

Python f-string power for your filenames, minus the typing

By ethanfel·Created 7 months ago·Updated 2 months ago· 2
String Format
  • v0
  • v1
  • v2
  • v3
  • v4
  • v5
  • v6
  • v7
  • string
template{0}/{1}

String Format is the pack's answer to the eternal ComfyUI ritual of chaining three text nodes together just to get a filename like shot_0012.png. You give it a Python format template, wire up to eight values, and it hands back one assembled string. It's the same str.format engine Python uses, so it's exactly as expressive as the thing you already half-know - just without writing a line of code.

The input that does all the work

  • template (default {0}/{1}) - a Python format string. Positional {0}, {1}… map to the connected inputs in order.

That's the whole trick: the template is Python format syntax, not %-style or a hand-rolled join. That unlocks zero-padding and conversions in one line:

  • {1:04d} zero-pads an integer to four digits - 12 becomes 0012.
  • {0:06.2f} formats a float as fixed-width, two decimals.
  • {1} followed by a literal like _v2 is just plain text between fields.

Those conversion specifiers are the real reason to reach for this node instead of a string-concat chain. Concat nodes can't pad; this one does, and it does it in a single widget you can see at a glance.

The inputs and output that matter

The eight optional inputs v0v7 are typed as * (any), so you can feed them from a JSON loader, a primitive, a seed node - anything. If a value is already a string it's used as-is; numbers get formatted per the template's specifier. You only have to wire the slots your template actually references; unwired ones default to empty strings.

Output is a single string (STRING) - wire it into a save node's filename prefix, a LoadImage path, a text encoder, or a display node.

One behavior worth knowing: if the template references {5} but you only wired v0v2, you don't get a crash. The node catches the format error and returns a literal [format error: ...] string instead, which is much easier to debug than a silent empty output - though it means a broken template looks like valid text until you read it closely. Keep templates and inputs in sync.

Install

Part of ComfyUI-JSON-Dynamic. ComfyUI Manager → search JSON Dynamic Loader, or:

cd ComfyUI/custom_nodes
git clone https://github.com/ethanfel/ComfyUI-JSON-Dynamic.git
# restart ComfyUI

No dependencies beyond what ComfyUI ships.

When you'd actually use it

This node earns its keep the moment you're assembling filenames or paths from parts - a sequence_number from the JSON loader, a camera name, a seed, all padded and joined into one output/shot_0012_camA_seed77.png. That's a three-node chain (concat + a couple of string primitives) collapsed into one. If you just want to glue two strings together, it's overkill; if you want formatting, it's the one I'd reach for.

CategoryJSON Dynamic/string

Inputs (9)

NameTypeDefaultDescription
templateSTRING{0}/{1}
v0opt*
v1opt*
v2opt*
v3opt*
v4opt*
v5opt*
v6opt*
v7opt*

Outputs (1)

NameTypeDescription
stringSTRING