Nodes/ComfyUI-JoyCaption/Caption Saver 📝
ComfyUI Node

Caption Saver 📝

The node that turns a caption string into a training-ready .txt file

By 1038lab·Created about a year ago·Updated 7 months ago· 295
Caption Saver 📝
  • image
    string
    image_path
    custom_output_path
    custom_file_name
    overwritetrue

    This node has no outputs. That's not a limitation, it's the point - Caption Saver is the last stop in a caption-generation pipeline, the node that actually writes a caption to disk as a .txt file. If you've wired up JoyCaption to auto-caption a folder of LoRA training images, this is what turns the caption string sitting in ComfyUI's memory into the file your trainer actually reads.

    That file layout matters more than it looks like it should. Kohya's sd-scripts, AI Toolkit, OneTrainer, basically every LoRA trainer in current use expects an image and its caption to sit side by side with matching filenames: portrait_01.png next to portrait_01.txt. Get that pairing wrong and your trainer either skips the image or, worse, pairs it with the wrong caption. That's exactly the file this node produces, which is why it exists as a dedicated node rather than a generic file-write node - the pack's "Caption Tools" are built to close this loop without leaving ComfyUI.

    The inputs that matter

    • string - the caption text itself. This is what you wire the output of a JoyCaption node into.
    • image_path - the path to the image this caption belongs to. By default, the saved caption's filename and location are derived from this, which is how the node keeps image and caption paired correctly. If you're batch-processing a folder, this should come from the same Image Batch Path node run that supplied the image to your JoyCaption node in the first place - don't hand-type it or source it from somewhere else, or you risk pairing a caption with the wrong file.
    • image (optional) - if you also want a copy of the image saved alongside the caption, wire it here.
    • custom_output_path and custom_file_name (optional) - override where the file goes and what it's named, instead of deriving both from image_path.
    • overwrite - defaults to true. If true, re-running the workflow on the same image silently replaces the existing caption file. If false, the node appends a number to keep the filename unique instead of overwriting.

    There's nothing downstream of this node by design - it's marked as an output node in ComfyUI's graph, meaning it's a valid endpoint for execution even with nothing wired out of it.

    How the whole pipeline fits together

    The pattern this pack is built around: Image Batch Path loads a folder of training images and hands you back both the images and their file paths as parallel lists. Each image goes into a JoyCaption node (GGUF or standard), which produces a caption string. That string, plus the matching path from Image Batch Path, both go into Caption Saver, which writes the .txt. Do that across a batch and you've turned an unlabeled image folder into a captioned dataset without touching a text editor. Worth remembering from how the community gets good LoRA results out of auto-captioning: describe the traits you want the LoRA to treat as adjustable, and leave the traits you want baked in undescribed - a caption that over-describes a character's hair color teaches the model that hair color is variable when you wanted it fixed. Whatever this node writes is exactly what your trainer will read.

    How to install it

    Search "ComfyUI-JoyCaption" in ComfyUI Manager, or manually:

    cd ComfyUI/custom_nodes
    git clone https://github.com/1038lab/ComfyUI-JoyCaption.git
    cd ComfyUI-JoyCaption
    pip install -r requirements.txt
    

    Caption Saver itself has no model to download and no heavy dependency of its own - it's a plain file-writing node, so if all you need from this pack is this and Image Batch Path, you can skip the whole llama-cpp-python / GGUF install dance entirely.

    Common issues & troubleshooting

    Your captions from a re-run vanished. That's overwrite defaulting to true. If you're iterating on prompt styles and want to compare outputs rather than replace them, flip it to false so each run gets a uniquely numbered file instead of clobbering the last one.

    Captions end up on the wrong image. Almost always a wiring mistake - image_path didn't come from the same source as the image that actually got captioned. If you're batching, trace both back to the same Image Batch Path node and make sure the list indices line up.

    A caption file is empty or looks malformed. This node doesn't validate what it's handed - it writes whatever string arrives. If your JoyCaption node upstream failed or returned nothing (a bad quant load, an OOM that got silently caught, whatever), you'll get an empty .txt instead of an error here. Worth spot-checking a handful of files early in a large batch run rather than trusting all of them blind.

    Category🧪AILab/📝JoyCaption

    Inputs (6)

    NameTypeDefaultDescription
    stringSTRING
    image_pathSTRING
    imageoptIMAGE
    custom_output_pathoptSTRING
    custom_file_nameoptSTRING
    overwriteoptBOOLEANtrueif true, will overwrite the existing txt file, if false, will add a number to the filename to make it unique

    Outputs (0)

    No outputs