Nodes/m9-prompts-comfyui/EvaluateStringMultiline [m9]
ComfyUI Node

EvaluateStringMultiline [m9]

One text box, and a different prompt every run

By MarcusNyne·Created 3 years ago·Updated 15 days ago· 2
EvaluateStringMultiline [m9]
    • text
    • random_line
    ◄value►
    ◄seed_optional0►

    A text box that rolls a die

    Strip it back and this is the stock PrimitiveStringMultiline - same single multiline widget, same string going out. Then it does two extra things that turn one node into a tiny prompt-randomiser:

    1. Any { one | two | three } in your text collapses to one of the options.
    2. It picks a random line of the result and gives you that as a second output.

    That's it. It's not a wildcard engine: no wildcard files, no ranges, no seed table. But if what you want is "each run, pick a hair style off my list," it's the shortest path in ComfyUI, and it works on any string - a prompt, a filename fragment, the replace field of a StepReplace [m9] node.

    Inputs and outputs

    value is the only required field: a multiline STRING. seed_optional is an optional INT (default 0, which is the value an unconnected socket sends).

    Two STRING outputs:

    • text - the whole thing, choices resolved.
    • random_line - one line drawn from that resolved text.

    random_line is the reason to reach for this over the stock primitive: lines are trimmed, blank lines are never picked, a single-line value always returns itself, and empty text returns empty - so a stray newline at the bottom of your box can't surprise you.

    The author's own example workflow is exactly the two clean uses side by side. A node holding {blue|green} feeds a StepReplace [m9] search-and-replace pair, so eye colour is a coin flip. A second node holds five hair prompts, one per line, and its random_line feeds another StepReplace replacement - template stays fixed, fill-in-the-blank varies.

    The { a | b } rules

    This is old A1111 wildcard syntax that most people who arrived after 2024 never learned (see prompt-engineering.md § the bracket trick - it's the same {brown|blonde|black} idiom). The version here is a bit tidier:

    • Options are trimmed, so { a | b } and {a|b} are identical.
    • An empty option is legal: { a | } sometimes picks nothing at all.
    • They nest: { a | { b | c } }.
    • Braces without a | are left alone, so {like_this} and lora syntax like <lora:foo:0.8> survive untouched.
    • \{, \| and \} are literal characters.

    One nuance worth knowing before it bites you: in value, each occurrence of a choice rolls separately. {x|y} mid {x|y} can quite legitimately come back as y mid x. If the same value needs to appear in three places consistently, roll it once in its own node and wire the text output into the three places - which is precisely why the example workflow gives eye colour its own box instead of inlining it into the main prompt.

    The caching trap, and the seed

    Here's what everybody gets wrong on the first try, and it's a ComfyUI rule, not a bug in this node: leave seed_optional unconnected and you still get a new roll every run - the node reports itself dirty via IS_CHANGED, so it re-executes instead of serving one cached result forever. Leave it at 0 and it behaves the same way. Any other value makes the run reproducible: same seed, same fields, same text, every time.

    So the usual workflow is: leave it at 0 while you're exploring, then when a run gives you something you like, wire a seed primitive in and lock it.

    The cost is real, and it's the same cost described in comfyui-node-plumbing.md § the always-rerun trick: a node that never settles defeats the cache for everything behind it. One always-dirty randomiser is fine. Four of them in a chain is how you end up with a workflow that feels mysteriously slow, re-encoding prompts every single queue.

    Install

    ComfyUI Manager → search m9-prompts-comfyui, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/MarcusNyne/m9-prompts-comfyui
    

    Restart. No requirements.txt, no models, no dependencies beyond ComfyUI itself - the pack is plain Python. The node lands in utilities/primitive, right beside the stock primitive it extends.

    Common problems

    • The same text every run. A seed is wired in from somewhere you forgot, or the saved workflow already has a fixed value in seed_optional. Set it back to 0.
    • Choices not expanding, or braces showing up in the output. You need the pipe. A {...} with no | is deliberately left as literal text, and {a,b} isn't a choice either.
    • Different options in one prompt. That's the independent-roll behaviour above. Roll once, reuse the text output.

    This pack is obscure - a single-author ComfyUI port of the older A1111 sd-scramble-prompts-m9 extension, with essentially no community discussion to lean on. Nothing suspicious about it; it just never got famous. If you want prompt variety without a wildcard extension, it's a two-minute win.

    Categoryutilities/primitive

    Inputs (2)

    NameTypeDefaultDescription
    valueSTRING—
    seed_optionaloptINT00–18446744073709550000—

    Outputs (2)

    NameTypeDescription
    textSTRING—
    random_lineSTRING—