ComfyUI Node

Caption File Saver

Write training captions to disk without the kohya chore

By kinorax·Created 5 months ago·Updated about a month ago· 2
Caption File Saver
    • caption
    • file_stem
    • file_path
    file_stemcaption
    caption
    path_sourceinput
    path.

    LoRA training runs on a boring convention: every image gets a same-name .txt file beside it, and the caption inside is what the model learns. image_0001.png gets image_0001.txt. Get a few hundred of those right and you have a dataset; get the filenames mismatched and you have a training run that quietly learns garbage. Caption File Saver exists to make the "write the text files" part of that pipeline a node instead of a script.

    It's the caption half of the pack's dataset tooling, designed to sit at the end of a graph that classifies or captions images - feed it a list of captions and file stems, and it writes the .txt files into a directory you choose, under either ComfyUI's input or output tree.

    How it works

    The core inputs are what you'd expect:

    • file_stem (default "caption") - the output filename without extension. For a batch, provide one stem per item.
    • caption - the caption text (or a list of captions) to save.
    • path_source - input or output, which base directory to write under.
    • path - the relative directory under that base (default .).

    The node validates as it goes: it rejects filenames with illegal characters and Windows-reserved names like CON and PRN, so a bad stem fails loudly instead of producing a file you can't open later. In batch mode it requires the caption and stem lists to line up (one per item, or a single caption reused for all) and errors if the counts disagree.

    Outputs are the resolved data echoed back for convenience: caption and file_stem lists, plus file_path - the full path of each written file. Because it writes to disk, it's flagged as an output node, meaning ComfyUI treats it as a terminal step that always executes.

    Where it fits in a real dataset pipeline

    The natural chain in this pack: Image Directory Reader loads a folder of images (returning each image, its caption if one already exists, and its file stem), a tagger or Caption step generates new caption text, and Caption File Saver writes the .txt files. The README even notes that Image Directory Reader can connect its path_source and path outputs straight into this node - the plumbing is designed for exactly that loop.

    For training specifically, this is the "caption by hand, in the graph" workflow: you review and edit captions as text nodes, then write them all in one pass. It's not a replacement for bulk-tagging tools, but it beats building an ad-hoc script to do the same write.

    The honest caveats

    Filename hygiene is on you for the content - the node validates stems but won't stop you from overwriting an existing file with the same stem, so batch runs can clobber earlier captions. And "input/output subdirectory" is deliberate: this writes inside ComfyUI's folders, not arbitrary absolute paths, which keeps it sandboxed to where ComfyUI is allowed to write. If you need captions written next to a dataset outside ComfyUI's tree, you'll want to symlink that folder into input and point path at it.

    Installing

    Part of kinorax/comfyui-info-prompt-toolkit:

    cd ComfyUI/custom_nodes
    git clone https://github.com/kinorax/comfyui-info-prompt-toolkit.git
    cd comfyui-info-prompt-toolkit
    pip install -r requirements.txt
    

    or install "Info-Prompt-Toolkit" via ComfyUI Manager, then restart. No model files. If you're building a training set, pair it with Image Directory Reader and Image Saver (which can also write same-name captions via its write_caption toggle) - the pack's whole caption ecosystem is in the same install.

    CategoryInfo-Prompt-Toolkit/ImageInfo

    Inputs (4)

    NameTypeDefaultDescription
    file_stemSTRINGcaptionOutput filename without extension; for batch save, provide one stem per item
    captionSTRINGCaption text or caption list to save as txt files
    path_sourceCOMBOinputBase directory for path
    pathCOMBO.Directory path relative to selected base directory

    Outputs (3)

    NameTypeDescription
    captionSTRING
    file_stemSTRING
    file_pathSTRING