Prompt Snippet Extractor
Your LoRA caption file, served one snippet at a time
- prompt
- prompt_text
- filename_to_label
- filename
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_labelis the cleaned version - leading numbers stripped ifignore_start_number_labelis on, underscores turned into spaces (smile front). Drop that into a label or a tag and it's already presentable.prompt_textis the rest of the snippet with the filename stripped, so it's clean to feed a text encoder.promptis 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_indexis 0-based. Your second caption is index 1, and indexing past the end raises a hardValueError- the node refuses gracefully, then kills the run. Count from zero. - Empty
prompt_listreturns 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.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| prompt_list | STRING | — | |
| snippet_index | INT | 00–999 | — |
| split_char | STRING | -- | — |
| first_word_is_filename | BOOLEAN | true | — |
| ignore_start_number_label | BOOLEAN | true | — |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| prompt | STRING | — |
| prompt_text | STRING | — |
| filename_to_label | STRING | — |
| filename | STRING | — |