Nodes/DJZ-Nodes/Captions To Prompt List
ComfyUI Node

Captions To Prompt List

Turn a caption folder into one giant prompt list in seconds

By MushroomFleet·Created 2 years ago·Updated 5 months ago· 78
Captions To Prompt List
    • combined_captions
    • output_filename
    directory_path/path/to/dataset
    reloadfalse

    If you've ever needed all the captions from a training dataset as one searchable blob - say, to find which tags dominate, or to sample lines for a prompt experiment - you know how tedious it is to concatenate fifty .txt files by hand. CaptionsToPromptList walks a directory tree, reads every caption file, and hands you a single combined string plus a suggested output filename. It's a dataset utility, not a creative node, and it's exactly the kind of thing DJZ-Nodes throws in alongside its fancier stuff.

    How it works

    The mechanism is simple and honest: it uses os.walk to recurse through directory_path, and for every .txt file it reads the lines and appends them to one list, then joins everything with newlines. Outputs are combined_captions (STRING) and output_filename (STRING) - the latter is just the folder's name plus .txt, e.g. my_dataset.txt, meant to save you from typing the same name into SaveText.

    The reload toggle is the one clever bit. ComfyUI caches node results; with reload off, the node only recomputes when the input directory_path changes. Flip reload on and it computes an MD5 hash of every caption file's contents, so it re-runs when any caption changes - useful while you're actively editing captions and the graph should pick up the edits.

    What it's for

    Two main workflows:

    • Dataset QA - dump combined_captions into a text viewer or a wordcloud node to eyeball tag distribution before training a LoRA. The KB's lora-training essay is firm that caption quality is the hidden variable in LoRA results, and this is the cheap way to inspect what you actually have.
    • Prompt source material - wire the output into a text-splitter or into the Zenkai prompt nodes in the same pack to sample real captions as prompt fragments.

    It ignores non-.txt files with a console message (except .png, which it skips silently), and it prints the path of every file it processes - noisy in the log, but reassuring for large runs.

    Installing

    It's part of DJZ-Nodes (MushroomFleet / Drift Johnson). Grab the pack:

    cd ComfyUI/custom_nodes
    git clone https://github.com/MushroomFleet/DJZ-Nodes
    cd DJZ-Nodes
    pip install -r requirements.txt
    

    Or "DJZ-Nodes" through ComfyUI Manager. The node itself is pure stdlib (os + hashlib), so no extra dependencies.

    Gotchas

    • Point it at the folder containing the caption files, not a single file. It recurses, so a nested dataset layout works fine.
    • It reads every line of every caption as a separate entry - a multi-line caption becomes several lines in the output. Usually that's what you want; just don't be surprised by the line count.
    • With reload on and a huge dataset, the hashing pass adds startup time on every run. Leave it off unless you're actively editing captions.
    Categorycustom/text

    Inputs (2)

    NameTypeDefaultDescription
    directory_pathSTRING/path/to/dataset
    reloadoptBOOLEANfalse

    Outputs (2)

    NameTypeDescription
    combined_captionsSTRING
    output_filenameSTRING