Nodes/ComfyUI-Prompt_util_pack/Prompt Snippet Extractor
ComfyUI Node

Prompt Snippet Extractor

Your LoRA caption file, served one snippet at a time

By fmartinellidev·Created 8 months ago·Updated 8 months ago· 0
Prompt Snippet Extractor
    • prompt
    • prompt_text
    • filename_to_label
    • filename
    prompt_list
    snippet_index0
    split_char--
    first_word_is_filenametrue
    ignore_start_number_labeltrue

    The Prompt Snippet Extractor is the pack's answer to a specific, boring problem: you have a text file with two hundred captions in it, and you want to generate one image per caption without pasting them into the graph one at a time. If you've ever hand-built a dataset for LoRA training or a character-reference batch, you know this pain. This node splits a multi-prompt document on a delimiter and hands you one entry - the prompt, a filename, and a cleaned label.

    The setup that makes it sing: your caption file uses one snippet per line-group, each starting with a filename token. Think 001_smile_front on its own line, then the caption, then -- before the next entry. That's dataset-generation fuel: the filename drives your SaveImage prefix, and the caption drives the sampler.

    How it works

    The node does a few quiet cleanups first: an em-dash followed by spaces (-) becomes and, and + becomes ,. That's a nice touch if your captions were written by someone who thinks punctuation is decoration - it keeps token soup out of the prompt. Then it splits the document on split_char, picks the entry at snippet_index, and does the filename dance:

    • The first word of the snippet becomes filename (e.g. 001_smile_front).
    • filename_to_label is the cleaned version - leading numbers stripped if ignore_start_number_label is on, underscores turned into spaces (smile front). Drop that into a label or a tag and it's already presentable.
    • prompt_text is the rest of the snippet with the filename stripped, so it's clean to feed a text encoder.
    • prompt is the full snippet including the first word, if you want the raw thing.

    Inputs to know: prompt_list (multiline, your document), snippet_index (which entry, starting at 0), split_char (the delimiter - default --, not the --- the README claims), first_word_is_filename (turn the whole filename mechanic off if your snippets don't have one), and ignore_start_number_label.

    Where people get burned

    • Off-by-one is the classic. snippet_index is 0-based. Your second caption is index 1, and indexing past the end raises a hard ValueError - the node refuses gracefully, then kills the run. Count from zero.
    • Empty prompt_list returns all empty outputs. No error, just four blank strings. If everything downstream suddenly goes quiet, check that your text actually arrived.
    • The README's example says ---; the code's default is --. Copy the delimiter from the node, not from the docs.

    Why you'd reach for it

    LoRA dataset generation is the flagship use, and it leans on a truth the training guides keep repeating: dataset curation beats every other knob. This node is the plumbing half of that - it turns a well-organized caption file into a repeatable batch, with a filename for every output so you know exactly which image trained on which caption. It also pairs with the rest of the pack: prompt_text feeds the Hidden Processor for variation, the output chain runs through the Substitutor, and the filename goes straight to SaveImage.

    Installation

    Pure Python, no dependencies, no model files - it ships in a four-node pack:

    cd ComfyUI/custom_nodes
    git clone https://github.com/fmartinellidev/ComfyUI-Prompt_util_pack
    

    Restart ComfyUI, or find "Prompt_util_pack" in ComfyUI Manager. Works with any checkpoint. Just remember the README is stale in places - the delimiter default is the one spot where it'll actually bite you.

    Categoryprompt/util_pack

    Inputs (5)

    NameTypeDefaultDescription
    prompt_listSTRING
    snippet_indexINT00–999
    split_charSTRING--
    first_word_is_filenameBOOLEANtrue
    ignore_start_number_labelBOOLEANtrue

    Outputs (4)

    NameTypeDescription
    promptSTRING
    prompt_textSTRING
    filename_to_labelSTRING
    filenameSTRING