Nodes/ComfyUI-LZNodes/LZ Prompt Replace String
ComfyUI Node

LZ Prompt Replace String

Inline wildcard swapping with zero files

By liz-ils·Created 7 months ago·Updated 12 days ago· 1
LZ Prompt Replace String
    • result
    template
    placeholder_hair_
    candidates

    Every wildcard-replacement node in this family asks you to manage files. LZ Prompt Replace String is the one that doesn't: instead of pointing at a CSV, you type your candidate list straight into the node. One template, one placeholder, a multiline box of options - and each run swaps in a random line.

    For a quick session of variations this is the version I actually reach for. You're not building a reusable prompt library yet, you just want "the same scene, but with _hair_ being blonde / brunette / pink / bald, please." Making a file for that is friction; typing four lines into a box is not. The node reads the candidates box, splits it into non-empty lines, picks one at random, and substitutes it into the template. Done.

    The inputs

    • template (multiline) - your base prompt with the marker where the swap happens.
    • placeholder - the marker to replace. Default _hair_, but any literal string works.
    • candidates (multiline) - one option per line. This is the entire candidate pool; there's no file anywhere.
    • Output: result - the template with a random candidate substituted in.

    Empty candidates box? The template passes through unchanged. Empty placeholder? Also passes through. It's a forgiving node - it just won't do anything clever if you haven't told it to.

    How it behaves

    Literal string replace, random choice per execution - the same mechanism as the CSV cousins, just with inline data. One line, one option; a line that's only whitespace is skipped. There's no CSV-parsing to trip over, no escaping, no quoting. If you want a comma-containing value like a full sentence, it's still just one line - that's the advantage of line-delimited input over comma-delimited.

    Where it shines is interactive iteration: wire the result into a text encoder, change the candidates box between runs, and you've got a live prompt mixer. Pair it with LZTextPreview at the end of the string chain and you can see exactly which combination got chosen before it ever reaches the sampler.

    The honest limitations

    There's no persistence here - the candidates live only in the widget, so a shared workflow carries them embedded in the PNG, which is usually what you want, but you can't reuse one node's list elsewhere without copy-pasting. For that, upgrade to LZ Prompt Replace Single or Multi with a file in output/prompt_csv/. Also, this node handles one placeholder. If you need five simultaneous slots, LZ Prompt Replace Multi is the right tool; this one is deliberately minimal.

    One KB caveat worth keeping in mind: randomized substitution is a CLIP-model (SD 1.5/SDXL/Illustrious/Pony) workhorse, and it works fine on LLM-encoded models too as long as the substituted values read as normal language. Just keep placeholders out of parentheses and colons - weight syntax like (tag:1.3) is literal punctuation to LLM text encoders, and it'll show up in your prompt as such.

    Installing it

    Part of the ComfyUI-LZNodes pack:

    cd ComfyUI/custom_nodes
    git clone https://github.com/liz-ils/ComfyUI-LZNodes
    

    Restart ComfyUI, or install via ComfyUI Manager by searching "ComfyUI-LZNodes". No extra dependencies, no models to download.

    CategoryMyCustomNodes/Text

    Inputs (3)

    NameTypeDefaultDescription
    templateSTRING
    placeholderSTRING_hair_
    candidatesSTRING

    Outputs (1)

    NameTypeDescription
    resultSTRING