Nodes/Gprompts/String Formatter
ComfyUI Node

String Formatter

Build any string from any inputs

By GadzoinksOfficial·Created about a year ago·Updated 3 months ago· 3
String Formatter
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • formatted_string
format_stringThe prompt is $a, the seed is $b, width is $c, height is $d. Generated at $datetime on $hostname, Operating system $os

Somewhere in every long workflow you hit the moment where you need a string assembled from things that don't naturally live in the same place - a prompt here, a seed there, a date, a hostname. String Formatter is that assembly step. One template, up to eight inputs, and a pile of system variables, all jammed into a single output string. It's the pack's glue node: the thing that turns a GPrompts output into a readable note, or a seed into a filename component.

The mental model is sprintf or Python's format strings: write a template with $variables, plug things in, get a string out.

What goes in

The format_string template is the only required input, and the default shows the idea immediately:

The prompt is $a, the seed is $b, width is $c, height is $d. Generated at $datetime on $hostname, Operating system $os

a through h are eight wildcard inputs - wire anything, they get stringified automatically. So GPrompts' computed_prompt into a, a seed into b, and $a / $b resolve to the actual values.

Then there are the system variables, which are the fun part. The README lists them all, but the ones you'll actually use:

  • Time: $datetime, $date, $time, $timestamp, $weekday
  • Machine: $hostname, $os, $user, $cpu_count
  • ComfyUI paths: $model_dir, $input_dir, $output_dir, $temp_dir
  • Unique-ish: $uuid, $random_hex, $counter (a six-digit number that increments every execution), $batch_id
  • GPU (if torch is loaded): $gpu_name, $cuda_available

One output: formatted_string. That's the whole node.

Why you'd reach for it

The documented pairing is GPrompts → String Formatter → Save Image With Notes: build a note like "a smiling cat with seed 12345 on hal2000" and have it embedded in the PNG. That closes the loop on "what the hell made this image." Beyond that, it's the standard answer to anything that takes a string and should vary per run - notes, captions, folder organization via $date_path / $datetime_path, filenames, anything where hardcoding is going to bite you later.

A few mechanism details worth knowing

The substitution sorts variables by name length, longest first, so $datetime is replaced before $date - a classic token-replacement footgun the author explicitly handled. Values are snapshotted at execution time, so $datetime reflects when the node ran, not when you queued. And $counter lives on the node instance, incrementing per execution - reload the workflow and it starts over.

Install

Same pack as the rest:

cd ComfyUI/custom_nodes
git clone https://github.com/GadzoinksOfficial/comfyui_gprompts

restart, or search "Gprompts" in ComfyUI Manager. pillow is the only declared dependency (already there), no models, MIT.

Where people get burned

  • Plain-text replacement, not an escape hatch. A literal $ in your template that happens to match a variable name gets replaced. There's no escaping syntax, so if you're writing text that legitimately contains $hostname or similar, expect it to vanish.
  • No $ expansion in other nodes' prefix fields. String Formatter builds strings; it doesn't grant the power to, say, Save Image With Notes' filename_prefix, whose tooltip talks a good game about $variables but whose code only handles %-formatting. Generate your string here and paste the result - don't assume the target node will interpolate it for you.
  • $counter isn't global. It's per node instance, so two String Formatter nodes each have their own counter, and both reset when the workflow reloads. Fine for per-run labels, wrong tool if you wanted a session-wide sequence.
Categoryutils/text

Inputs (9)

NameTypeDefaultDescription
format_stringSTRINGThe prompt is $a, the seed is $b, width is $c, height is $d. Generated at $datetime on $hostname, Operating system $osTemplate string with $variables (e.g., $a, $datetime, $hostname). Use $a through $h for inputs.
aopt*Input A - any value (automatically converted to string)
bopt*Input B - any value (automatically converted to string)
copt*Input C - any value (automatically converted to string)
dopt*Input D - any value (automatically converted to string)
eopt*Input E - any value (automatically converted to string)
fopt*Input F - any value (automatically converted to string)
gopt*Input G - any value (automatically converted to string)
hopt*Input H - any value (automatically converted to string)

Outputs (1)

NameTypeDescription
formatted_stringSTRING