ComfyUI Node

LoRA Caption Save

The quiet half of the captioning pair that actually writes your dataset

By LarryJane491·Created 3 years ago·Updated 2 years ago· 80
LoRA Caption Save
      namelist
      path
      text
      prefix

      LoRA Caption Save is the unglamorous second half of the Image-Captioning-in-ComfyUI pack, and it deserves more credit than its 15 Google impressions suggest. Its sibling, LoRA Caption Load, feeds your images to the WD14 Tagger; this node takes the captions that come back and writes them to disk as .txt files, one per image. That's the step that actually makes your folder a training dataset - because every trainer worth using, from Kohya to ai-toolkit, expects a caption file sitting next to each image, named after it.

      If you've ever hand-renamed caption files to match images, you know why this exists. The Save node matches names for you.

      How it works

      Everything except the prefix is wired in - there are no widgets for the main inputs, so you connect them:

      • namelist - the Name list output from LoRA Caption Load, a newline-separated list of filenames.
      • path - the folder to write into (the Load node passes its own path through, so it's one wire).
      • text - the caption, which in the standard workflow is the WD14 Tagger's output.
      • prefix (optional, default " ") - a text string prepended to every caption. This is the widget that matters.

      The mechanism is straightforward: it splits the name list into lines, chops the .png off each one, then walks the list looking for the first image that doesn't already have a .txt and writes prefix + caption there. Because the name list and the image list come from the same Load node, they stay in lockstep even when your folder is a mess.

      The prefix input is your trigger-word slot, and it's the one thing worth understanding before you run. For an Illustrious/Pony/NoobAI set, captions are comma-separated Danbooru tags, so a trigger like mychar becomes mychar, 1girl, .... The README warns you to end the prefix with a comma, but the shipped code actually normalizes this for you - type mychar or mychar, and either way you get mychar, . One small laziness accounted for.

      The trap: existing caption files

      Here's the thing the README flags and that you will hit: if a caption file already exists for an image, the node throws an "Out of Range" error and the whole run dies. The code works by counting up until it finds a filename that doesn't exist, and when everything's already taken it runs off the end of the name list. The author says plainly they could fix it and don't see the point. Fair enough - the fix is trivial from your side:

      # clear old captions before re-running
      rm -f /path/to/your/dataset/*.txt
      

      Delete the old captions, queue the workflow again, done. Want to tweak captions? Same move.

      Installing

      Same pack as LoRA Caption Load - install it once and you get both nodes.

      # ComfyUI Manager: search "Image-Captioning-in-ComfyUI"
      # or manually:
      cd ComfyUI/custom_nodes
      git clone https://github.com/LarryJane491/Image-Captioning-in-ComfyUI
      

      Restart ComfyUI, then find the node under the LJRE category (or search "caption"). No extra dependencies, no model downloads - that part belongs to the WD14 Tagger it pairs with.

      The verdict: a dumb little node that does exactly one thing, and does it the way trainers expect. It's a rewrite of Inspire Pack and YMC Suite functions, unmaintained since 2024, and it's still the fastest way to caption a folder in ComfyUI. Just remember to clear those old .txt files first.

      CategoryLJRE/LORA

      Inputs (4)

      NameTypeDefaultDescription
      namelistSTRING
      pathSTRING
      textSTRING
      prefixoptSTRING

      Outputs (0)

      No outputs