ComfyUI Node

Formatted String

Filenames, labels, and mid-template prompts without another string node

By geroldmeisinger·Created 9 months ago·Updated 2 days ago· 184
Formatted String
  • a
  • b
  • c
  • d
  • string
fstring{a}_{b}_{c}_{d}

Once you're combining lists, you immediately need the glue: take the subject from one list and the style from another and turn them into an actual prompt, or a filename, or a label. Formatted String is that glue, and it's one of those nodes you don't appreciate until the third time you reach for it.

It takes a template with placeholder variables and substitutes in up to four values. The format syntax is Python's str.format(), which means it's far more capable than the "concatenate two strings" nodes scattered through the ecosystem - and it's exactly what the pack's "Combine prompts" example uses to merge unzip_a and unzip_b into "a {a} with a {b} hat".

What you can do with it

  • {a:.2f} - round a float to 2 decimals. Invaluable when your LoRA strength comes out as 0.6999999.
  • {a:05d} - pad to 5 leading zeros, so your filenames sort next to ComfyUI's native ComfyUI_00001_.png suffix.
  • {{ }} - doubled braces for literal braces, so you can build JSON strings inside the template.
  • Search & replace syntax like %date:yyyy-MM-dd hh:mm:ss% and %KSampler.seed% - this runs in JavaScript before execution, so you can use the node as a GET-node to pull a value out of another node (the seed, an image's width) without wiring it. Filenames like %date:yyyy-MM-dd%_{a} work in a Save Image prefix.

Inputs and output

fstring (multiline template) plus four optional wildcard inputs, a, b, c, d - wire an output list into any of them and the template gets re-evaluated per item, which is exactly what makes prompts out of combinations. The string output is a plain string, not an output list; that's correct behavior here, since the calling node runs per item.

The README's row/column filename example shows the payoff: combine two lists, feed the combination's index and the two unzip values into a template like img_{c:02d}_row_{ad}_col_{b}, and every grid image saves with a name that tells you exactly what it was.

Installing

Search "OutputLists Combiner" in ComfyUI Manager, or clone into ComfyUI/custom_nodes and uv pip install -r requirements.txt from the pack folder, then restart. No extra dependencies beyond the pack's shared set.

One real gotcha: if you pipe an output list straight into {a}, you do not get a list out of the string output - the node formats once per invocation, and the downstream node runs once per value. That's the desired behavior for prompt building, but it surprises people who expect a batch text node. For displaying every value at once (debugging), use a Show Text node instead.

CategoryUtility

Inputs (5)

NameTypeDefaultDescription
fstringSTRING{a}_{b}_{c}_{d}Creates a string that contains placeholder variables and replaces them with their respective values. Uses python `str.format()` internally, see [Python - Format String Syntax](https://docs.python.org/3/library/string.html#format-string-syntax) . * You can use `{a:.2f}` to round off a float to 2 decimals. * You can use `{a:05d}` to pad up to 5 leading zeros to fit with comfys filename suffix `ComfyUI_00001_.png`. * If you want to write `{ }` within your strings (e.g. for JSONs) you have to double them: `{{ }}`. Also applies *search & replace (S&R) syntax* such as `%date:yyyy-MM-dd hh:mm:ss%` and `%KSampler.seed%`. Thus you can also use it as a `GET-node`. Note that "search & replace" takes place in Javascript context and runs before node execution.
aopt*(optional) value that will be as a string at the `{a}` placeholder.
bopt*(optional) value that will be as a string at the `{b}` placeholder.
copt*(optional) value that will be as a string at the `{c}` placeholder.
dopt*(optional) value that will be as a string at the `{d}` placeholder.

Outputs (1)

NameTypeDescription
stringSTRINGThe formatted string with all placeholders replaced with their respective values.