🐟String Formatter
Full Python f-string formatting inside ComfyUI
- arg1
- arg2
- arg3
- arg4
- arg5
- arg6
- arg7
- arg8
- arg9
- arg10
- formatted_string
🐟String Formatter gives you real Python f-string formatting in the graph - not the fixed placeholder replacements most ComfyUI text nodes offer, but the whole syntax: number padding, string width, dict formatting, conditional expressions if you want to get silly. If you've ever wanted to build a prompt like "{arg1} in the style of {arg2}, {arg3:>20}" and have it actually respect the format spec, this is the node.
How it works
One required input, template, a multiline string written in f-string syntax. Then arg1 through arg10 - ten optional inputs that accept any type (*), so you can plug in strings, numbers, lists, dicts, whatever. Your template references them as {arg1}, {arg2}, and so on, and the node assembles the final string.
template: "你好 {arg1},欢迎来到 {arg2}!"
arg1: 小明 arg2: ComfyUI
→ "你好 小明,欢迎来到 ComfyUI!"
Numbers, dicts, and lists all format naturally - {arg1} with a dict input prints the dict's repr, which makes it handy for injecting structured metadata into a prompt. The output is formatted_string, and the node also displays it on the graph (there's a small JS extension that renders the result in a read-only widget), which is a nice touch for prompt work.
Two things the README gets wrong
The README claims unprovided arguments are "ignored" and that referencing one gives a Format Error. Tested against the actual code: an unprovided arg defaults to None, and {arg2} formats as the literal text None in your output. So a template with a missing arg silently prints "None" into your prompt - keep an eye on that, because it's exactly the kind of quiet corruption you'll blame on the model.
Second: the template is evaluated with Python's eval. That's what buys you full f-string syntax, and it's also the thing to respect. Builtins are reachable - your template could in principle call __import__('os') and run arbitrary code. That's fine for your own workflows (it's your machine, your templates), but don't paste a template you don't trust from a stranger's workflow. Treat templates as code.
Error handling
If the template fails - a typo'd variable, an unterminated format spec - you get a Format Error: <message> string on the output instead of a crash, plus the result shown on the node. It's forgiving enough to debug live, but remember the None behavior above; not every problem announces itself.
Installing
ComfyUI Manager, search "ComfyUI-String-Helper", install, restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/liuqianhonga/ComfyUI-String-Helper.git
The pack ships translators and chardet as dependencies, but this node is pure stdlib - no translation, no models, no network.
Where it fits
Use it anywhere you'd use the built-in Text Concatenate but need real formatting - numbers padded for filenames, dates spliced into prompts, model metadata folded into a text string that feeds a CLIP encoder. For the heavy lifting on dynamic prompt assembly, pair it with StringMatcher (conditional value picking) and StringConverter (typed output), and you've got a mini templating engine with no external services.
Inputs (11)
| Name | Type | Default | Description |
|---|---|---|---|
| template | STRING | — | |
| arg1opt | * | — | |
| arg2opt | * | — | |
| arg3opt | * | — | |
| arg4opt | * | — | |
| arg5opt | * | — | |
| arg6opt | * | — | |
| arg7opt | * | — | |
| arg8opt | * | — | |
| arg9opt | * | — | |
| arg10opt | * | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| formatted_string | STRING | — |