Nodes/comfyui-adaptiveprompts/✂️ Prompt Splitter ✂️
ComfyUI Node

✂️ Prompt Splitter ✂️

Randomly trim sections out of a prompt (and keep the leftovers)

By Alectriciti·Created 12 months ago·Updated 23 days ago· 87
✂️ Prompt Splitter ✂️
    • Trimmed
    • Scraps
    string
    quantity1
    quantity_modeREMOVE
    keep_first_sections0
    modeRANDOM
    delimiter,
    seed0

    Sometimes a prompt has too many tags, and you want variation that comes from removing things rather than adding them. PromptSplitter takes a prompt, splits it into sections on a delimiter, and randomly (or deterministically) trims some of those sections away - while handing you back both halves, so nothing you cut is actually lost.

    How it works

    The pack defines a "section" as the text between two delimiters - comma by default, so masterpiece, best quality, 1girl is three sections. PromptSplitter decides how many sections survive using quantity and quantity_mode: set quantity_mode to REMOVE and quantity is how many sections get cut; set it to KEEP and quantity is how many sections you end up with, full stop, regardless of how many you started with. These two modes mean the same number in the quantity field does opposite things depending on the mode - worth double-checking which one you've got set before you queue a batch.

    mode controls where in the prompt the cuts land, and this is where the node gets genuinely useful for controlled variation rather than pure chaos: RANDOM removes uniformly, RANDOM_GRADUAL ramps the removal chance up as you move later into the prompt, RANDOM_EXPONENTIAL barely touches the early prompt then ramps hard near the end, RANDOM_SQRT is the inverse - aggressive early, flattens out later - RANDOM_MIDDLE concentrates trims around the center, and TRIM_BEGINNING / TRIM_END are flat deterministic chops from one side. keep_first_sections is your safety net on top of all of this: however many leading sections you set here are never touched, no matter what the mode or the RNG decides - the obvious use is pinning your subject and quality tags at the front while letting everything after them get shuffled by the odds.

    The inputs and outputs that matter

    • string - the prompt to process.
    • quantity / quantity_mode - how many sections, interpreted as either REMOVE-this-many or KEEP-exactly-this-many.
    • mode - where the trims land (see above).
    • keep_first_sections - leading sections that are always protected.
    • delimiter - what splits the prompt into sections (default ,).
    • seed - 0 for a fresh random result each run, fixed for reproducibility.
    • Outputs: Trimmed (what survived) and Scraps (what got cut) - route Scraps into a PromptMixer or a log node instead of discarding it if you want to reuse the cut material elsewhere.

    How to install it

    Install the whole pack via ComfyUI Manager (search comfyui-adaptiveprompts), or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Alectriciti/comfyui-adaptiveprompts
    

    then restart. No models or heavy dependencies - it's a pure text-processing node like the rest of the pack.

    Common issues & troubleshooting

    Nothing gets split. If your prompt uses newlines or a custom separator instead of commas, the default delimiter won't find any sections to work with - change it to match whatever actually separates your prompt's tags.

    You set quantity and got the opposite of what you expected. This is almost always the REMOVE/KEEP mix-up described above. A quantity of 5 in REMOVE mode strips 5 sections; the same 5 in KEEP mode trims everything down to only 5 sections remaining. Re-check quantity_mode first before assuming the RNG did something weird.

    keep_first_sections doesn't seem to protect what you expected. It counts sections, not tags separated by spaces or characters - count commas, not words, when deciding the number.

    Categoryadaptiveprompts/processing

    Inputs (7)

    NameTypeDefaultDescription
    stringSTRING
    quantityINT10–100The number of sections to either KEEP or REMOVE depending on QUANTITY_MODE.
    quantity_modeCOMBOREMOVEDetermines how 'quantity' is interpreted: REMOVE: Remove 'quantity' sections based on the selected MODE. KEEP: Ensure the final prompt has exactly 'quantity' sections (rest are trimmed).
    keep_first_sectionsINT00–100The number of sections at the beginning of the prompt to protect. These will never be trimmed, even if selected mathematically.
    modeCOMBORANDOMRANDOM: Removes random sections. RANDOM_GRADUAL: Probability of removal increases linearly as position moves forward. RANDOM_EXPONENTIAL: Very low chance early, then ramps up exponentially towards the end. RANDOM_SQRT: High chance early, flattens out later. RANDOM_MIDDLE: Highest chance to trim near the middle of the prompt. TRIM_BEGINNING: Absolutely removes from the start. TRIM_END: Absolutely removes from the end.
    delimiterSTRING,Character or string used to split the prompt into sections.
    seedINT00–2147483647Random seed for reproducibility. Use 0 for a random seed each run.

    Outputs (2)

    NameTypeDescription
    TrimmedSTRING
    ScrapsSTRING