Nodes/ComfyUI_StringEssentials/String Conditional Append
ComfyUI Node

String Conditional Append

Keep your prompt's keywords honest, without duplicates

By bradsec·Created 2 years ago·Updated 2 months ago· 36
String Conditional Append
    • output_string
    • was_appended
    input_string
    strings_to_check
    positionend
    match_casefalse
    separator,

    If you've ever had a quality-tag or style keyword vanish from a prompt because an LLM rewrote it, or balloon into three copies because a wildcard process added it twice, you know the exact problem this node exists for. String Conditional Append looks at your text, checks whether a list of strings is already present, and adds only the ones that are missing. It's a de-duplicator with an opinion, and it's genuinely one of the smarter small nodes in this pack.

    The classic use is a guaranteed-words tail. Say you feed an LLM-generated prompt into the sampler but never want it to lose masterpiece, best quality or a style token. You list those strings one per line, wire the prompt in, and get back a prompt that provably contains them - once. The "only if missing" bit is the whole point; a dumb append would stack the keyword every run and wreck the prompt weighting.

    How it works

    The node reads strings_to_check one line at a time. For each string, it checks whether that text is already a substring of the current result (case-insensitive by default), and appends it with the configured separator only if it isn't. Missing strings are added in the order you listed them. When it's done it hands back two outputs: the modified output_string, and a was_appended boolean that's true if anything was added.

    The inputs that matter

    • strings_to_check - one string per line. Each is checked independently, so you can protect five separate phrases in one go.
    • position - end (default) or beginning. Beginning is handy when the keyword is a quality anchor that should lead the prompt rather than trail it.
    • separator - what gets inserted between text and appended strings, default ", ". Change it to a space or a newline if your target syntax prefers it.
    • match_case - off by default, so anime in your check list counts as present even if the prompt says Anime. Flip it on if case actually matters to you.

    Outputs: output_string (STRING) and was_appended (BOOLEAN). That boolean is useful - feed it into a switch or notification node to know whether the workflow just modified your text.

    Installation

    Zero dependencies, zero model files - this pack is plain Python. Via ComfyUI Manager: Manager > Custom Nodes Manager > search "ComfyUI_StringEssentials" > Install, restart. Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/bradsec/ComfyUI_StringEssentials.git
    

    Restart, then find it under Add Node > utils > StringEssentials.

    Gotchas

    • The check is substring-based, not word-based. art in your check list matches artistic, and photo matches photorealistic. There's no whole-word toggle on this node, unlike String Strip and String Multi Replace - so if you need word-boundary matching, do that cleanup upstream with String Multi Replace instead.
    • One missing string appended is still was_appended = true, even if the other four were already there. It's a "did we touch anything" flag, not a per-string report.
    • Appends accumulate into the same result. Each missing string is appended to the result of the previous append, so with end position they stack in list order. That's almost always what you want.
    • Case-insensitivity is the default; if a phrase exists with different casing, it's treated as present and left alone.

    If your workflow ever needs "make sure these words are in the prompt" without "make sure these words are in the prompt twice", this is the node.

    Categoryutils/StringEssentials

    Inputs (5)

    NameTypeDefaultDescription
    input_stringSTRINGThe string to process
    strings_to_checkSTRINGEnter strings to search for and append if not found (one per line)
    positionCOMBOendWhere to add strings if not found
    match_caseBOOLEANfalseWhether the search should be case-sensitive
    separatorSTRING, Character(s) to use between text and appended strings

    Outputs (2)

    NameTypeDescription
    output_stringSTRING
    was_appendedBOOLEAN