ComfyUI Node

Format (str)

A prompt template where each piece lands where you say

By Elypha·Created 2 years ago·Updated 12 months ago· 0
Format (str)
    • STRING
    pattern[1], [2]
    str_1

    Concat (str) is the "put these in order" node. Format (str) is the "put this there" node. Instead of joining pieces with a separator, you write a template with numbered placeholders - [1], [2], [3] - and then connect your strings to the corresponding slots. It's the closest thing this pack has to a string-template function in node form, and it's the one you reach for when prompt order actually matters (which, for CLIP models, it does - see below).

    Mechanically it's dead simple: the pattern input (default "[1], [2]") is scanned, and every [i] placeholder is replaced with the value of the connected str_i input. The slots self-extend as you wire them, same as Concat (str). So with a pattern of "portrait of [1], [2] style", connecting str_1 = "a woman" and str_2 = "oil painting" gives you "portrait of a woman, oil painting style". You control exactly where each piece lands, including repeating a piece twice in the template.

    Where the order matters: on CLIP-era models, word order binds attributes - the KB's prompt-engineering essay makes the point that "Navia is eating cake, Clorinde is seated next to her" reads differently than the same content reordered, and template slots are a tidy way to lock in the order you want without retyping.

    The gotcha that will bite once

    The substitution only happens for slots that are actually connected. kwargs in the node contains only the inputs you wired, so the loop only knows about str_1 through str_N that exist. Leave str_2 unconnected in a pattern that references [2], and the literal text [2] passes through into your prompt. You won't get a crash - you'll get a prompt with a stray [2] in it, which then rides along into the encode. If your output looks wrong, check that every placeholder has a matching connected input.

    The inputs

    • pattern - the template, with [1], [2], ... placeholders
    • str_1 (and friends, appearing as you connect) - the values

    One output: STRING.

    Installing it

    Part of ComfyUI-Prompt-Helper - no extra dependencies, no models. ComfyUI Manager → ComfyUI-Prompt-Helper, or clone into custom_nodes:

    cd ComfyUI/custom_nodes
    git clone https://github.com/elypha/ComfyUI-Prompt-Helper
    

    Restart. Under prompt_helper.

    It's a small tool with a big usability payoff: instead of concatenation you get a template you can read at a glance, and if you share workflows, the pattern line doubles as documentation of what goes where.

    Categoryprompt_helper

    Inputs (2)

    NameTypeDefaultDescription
    patternSTRING[1], [2]
    str_1optSTRING

    Outputs (1)

    NameTypeDescription
    STRINGSTRING