Nodes/ComfyUI-GPT4V-Image-Captioner/String_Attribute_Selector
ComfyUI Node

String_Attribute_Selector

Merge two LoRA prompts and pick who wins per attribute

By 438443467·Created 3 years ago·Updated about a year ago· 27
String_Attribute_Selector
    • prompt
    • full_prompt
    • clear_text_A
    • clear_text_B
    • name_A
    • name_B
    text_Atext
    text_Btext
    prompt_typePriorityB

    This one's for people who keep two character or style prompts around and want to blend them without opening a text editor. You feed it two prompt strings - text_A and text_B - that use a [attribute:value] syntax, and it decides, per attribute, which value makes it into the merged prompt. The practical use case is LoRA prompt management: keep your "base character" prompt in A, your "variant" prompt in B, tag shared properties inside brackets, and let the node merge them for you.

    How it works

    Both texts are scanned with a regex that pulls out every [name:value] pair. For each attribute name found, the node looks at the values present in A and B and picks one:

    • Random - picks a random value from the union of A and B for every attribute.
    • PriorityB - always takes B's value (B's last one if repeated).

    Everything outside the brackets is treated as static text. The prompt output is the chosen attributes joined and wrapped in parentheses (value1,value2) - the classic weighted-group syntax for the CLIP encoder. full_prompt is clear_text_A + ',' + clear_text_B + ',' + prompt, i.e. both originals with the bracket attributes stripped, plus the winning selection on the end.

    Inputs and outputs

    • text_A, text_B - the two prompt strings. Both accept the [attr:value] syntax; plain text is fine too (it just passes through to the clear_text_* outputs).
    • prompt_type - PriorityB (default) or Random.

    Outputs: prompt, full_prompt, clear_text_A, clear_text_B, name_A, name_B. The name_* outputs are a nicety: each extracts the LoRA name from a <lora:name:weight> token inside the clear text, so you can see which LoRA is actually being referenced - useful when the strings come from somewhere you can't read at a glance.

    Honest notes

    The bracket syntax here is this node's own convention - it is not the standard [emphasis] weight syntax or A1111 wildcards. If you copy a prompt with square brackets expecting weight emphasis, the node will try to parse them as attributes. There's no eval, no files, no state - it's pure string surgery, so it's cheap to run and safe to trust. And the usual pack caveat applies: it was cut from the repo in the April 2025 rewrite, so the current install only ships the captioner; this node lives in the old Load_Image_Batch.py in git history.

    Install

    cd ComfyUI/custom_nodes
    git clone https://github.com/438443467/ComfyUI-GPT4V-Image-Captioner
    

    Restart ComfyUI. No dependencies beyond the pack's own short list. If you mostly want "randomly alternate between two prompts," simpler switch nodes do the job; reach for this one when you want per-attribute control over the merge.

    CategorySanmi Simple Nodes/Simple NODE

    Inputs (3)

    NameTypeDefaultDescription
    text_ASTRINGtext
    text_BSTRINGtext
    prompt_typeCOMBOPriorityB2 options: Random, PriorityB

    Outputs (6)

    NameTypeDescription
    promptSTRING
    full_promptSTRING
    clear_text_ASTRING
    clear_text_BSTRING
    name_ASTRING
    name_BSTRING