ComfyUI Node

String Formatter Tlant

Template Strings With Up to Ten Slots — the Prompt-Builder's Glue

By Tlant·Created 2 years ago·Updated 5 months ago· 2
String Formatter Tlant
    • formatted_string
    templateA {adj} {noun} in the style of {artist}.
    param1beautiful
    param2landscape
    param3
    param4
    param5
    param6
    param7
    param8
    param9
    param10

    If you've ever built prompts from parts - a fixed style block, a subject pulled from a random loader, an artist name from a dropdown - you know the pain of doing it with a pile of "Concatenate" nodes. This node does the same job in one place: you write a template with {} placeholders and feed it up to ten strings, and it fills the slots in order. It's the pack's general-purpose string assembler, and it's the node that holds all the other ones together in a real workflow.

    How it works

    The template uses Python's str.format with positional placeholders - {}, {}, {} - and the parameters fill them in order: param1 goes in the first {}, param2 in the second, and so on through param10. It collects params 1–10, sorts them, and formats. The error handling is friendlier than most: if you have more placeholders than params it pads with empty strings (instead of crashing with an IndexError), and if formatting fails for any reason it returns the original template and logs what went wrong.

    One honest gotcha hides in the default template: "A {adj} {noun} in the style of {artist}." looks like named placeholders, but they're not. Those {adj}, {noun}, {artist} are just three positional slots in disguise - param1 fills {adj}, param2 fills {noun}, param3 fills {artist}. Write {} for clarity, or remember the order.

    Inputs and outputs

    • template - the string with {} slots.
    • param1, param2 - always shown.
    • param3param10 - optional; right-click the node to reveal any of them.

    Output: formatted_string (STRING).

    Install

    Part of the Tlant pack:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Tlant/ComfyUI-OllamaPromptsGeneratorTlant
    

    restart, or search "String Formatter Tlant" in ComfyUI Manager.

    Where people get tripped up

    • Positional, not named. The slots fill strictly by order. If you feed param1 a noun and param2 an adjective, the noun lands first. Get the ordering right and you're fine.
    • Literal curly braces need doubling. Want a literal {} in the output? Python's format needs {{ and }} to escape them - the node doesn't save you from that.
    • Extra params are ignored, missing params are padded. That's the graceful part, but it also means a typo like {adj (unbalanced brace) will trip the formatter and give you the raw template back. Check the console - it prints the offending template.

    For anyone assembling prompts from parts, this is the glue node - ten slots, one template, no crashing. It won't change your life, but it'll change how many "concatenate" nodes you keep on screen.

    Categoryutils

    Inputs (11)

    NameTypeDefaultDescription
    templateSTRINGA {adj} {noun} in the style of {artist}.
    param1STRINGbeautiful
    param2STRINGlandscape
    param3optSTRING
    param4optSTRING
    param5optSTRING
    param6optSTRING
    param7optSTRING
    param8optSTRING
    param9optSTRING
    param10optSTRING

    Outputs (1)

    NameTypeDescription
    formatted_stringSTRING