Nodes/ComfyUI-TinyBee/Token Replace
ComfyUI Node

Token Replace

Build prompts from templates instead of by hand

By TinyBeeman·Created about a year ago·Updated 2 months ago· 1
Token Replace
    • result
    ◄templatethis will replace %0 with input_0►
    ◄token_count1►
    ◄input_0►
    ◄input_1—►
    ◄input_2—►
    ◄input_3—►
    ◄input_4—►
    ◄input_5—►
    ◄input_6—►
    ◄input_7—►
    ◄input_8—►
    ◄input_9—►

    If you've ever wanted to run twenty variations of the same prompt where only the subject changes, you know the pain of retyping it each time. Token Replace automates that: you write a template once with placeholder tokens like %0 and %1, and the node swaps them for whatever strings you feed in. One template, many prompts.

    The pattern is simple and powerful. Template: a %0 portrait of a %1, dramatic lighting. input_0 = cinematic, input_1 = fox. Result: a cinematic portrait of a fox, dramatic lighting. Change the inputs, keep the template, and every run produces a coherent prompt without touching the structure. It's the string-templating workhorse for prompt roulette and batch variation workflows - usually paired with a list node that feeds each variation through.

    How it works

    The template string can contain up to ten tokens, %0 through %9. Each is replaced by its matching input: %0 becomes input_0, %1 becomes input_1, and so on. Any token whose input isn't connected simply becomes an empty string.

    The inputs that matter:

    • template (STRING, multiline) - your prompt skeleton with %0…%9 placeholders.
    • token_count (INT, 1–10, default 1) - controls how many input slots the UI shows. It's a UI affordance, not a hard limit on replacement.
    • input_0 (STRING, required) through input_9 (STRING, optional) - the values that fill the tokens.

    The output is result - the fully assembled string, ready for your CLIP Text Encode or wherever prompts go.

    Installing it

    Token Replace comes from ComfyUI-TinyBee, a small MIT-licensed utility pack with no model downloads. Via Manager:

    1. ComfyUI Manager → Custom Nodes Manager.
    2. Search "ComfyUI-TinyBee" and install.
    3. Restart ComfyUI.

    Or clone:

    cd ComfyUI/custom_nodes
    git clone https://github.com/TinyBeeman/ComfyUI-TinyBee
    

    Restart and it's under 🐝TinyBee/Strings. No extra dependencies beyond what ComfyUI ships - jsonata in the pack's requirements is only for its JSON Parser node.

    Gotchas

    token_count is cosmetic: the replacement engine always tries all ten tokens, so if a template accidentally contains %7 but no input_7 is connected, that token quietly vanishes into an empty string - easy to miss and confusing when the prompt looks wrong. Also the token syntax is exactly %0–%9; a literal percent sign in your template is fine as long as it isn't followed by a digit you didn't mean to replace. And keep in mind the whole thing is a one-shot substitution, not a loop - if you want twenty variations from one template, feed the twenty values in from a list node rather than trying to make Token Replace iterate for you.

    Category🐝TinyBee/Strings

    Inputs (12)

    NameTypeDefaultDescription
    templateSTRINGthis will replace %0 with input_0—
    token_countINT11–10—
    input_0STRING—
    input_1optSTRING—
    input_2optSTRING—
    input_3optSTRING—
    input_4optSTRING—
    input_5optSTRING—
    input_6optSTRING—
    input_7optSTRING—
    input_8optSTRING—
    input_9optSTRING—

    Outputs (1)

    NameTypeDescription
    resultSTRING—