Nodes/ComfyUI-E-Tier-TextSaver/Text Saver (E-Tier)
ComfyUI Node

Text Saver (E-Tier)

Your Captions Are Full of <pad> Tokens. This Node Fixes That.

By e-tier-newbie·Created about a year ago·Updated about a year ago· 0
Text Saver (E-Tier)
    • text
    text
    filename
    text_to_remove<pad>
    save_toComfyUI/output

    If you've captioned images with Florence2 and then opened the resulting .txt file expecting a clean prompt, you've seen it: <pad> tokens sprinkled through your caption like confetti. Florence2 emits them, and if you're building a LoRA dataset you can't just leave them in - every caption file becomes one more thing to hand-clean. Text Saver (E-Tier) is a tiny node that strips the junk and writes a clean .txt in one step, on its way out of the graph.

    What it's actually for

    It sits at the tail of a dataset-prep pipeline: [Image Loader] → [Captioning Node] → [Text Saver (E-Tier)]. Training a LoRA needs a .txt caption next to every training image, and those filenames have to match. This node exists to make that step automatic - you caption with Florence2 (or a BLIP node, though the KB's current consensus is that BLIP is long past its sell-by date), drop the caption text in here, and get a matching .txt file written to disk.

    It's also an output node, so nothing downstream depends on it - it's the end of the line, deliberately.

    How it works

    Under the hood it's a plain Python node with one job: take the text, replace every occurrence of text_to_remove (default <pad>) with nothing, sanitize, and write the file. The three inputs that matter:

    • text - the caption, wired in from your captioning node (it's forceInput, so it must come from a wire, not a widget).
    • filename - the name to save as. It only takes the basename, strips any extension, and appends .txt, so you pass it your image filename and get my_image.txt. If it's empty you get untitled.txt.
    • save_to - a dropdown of output directories loaded from the pack's YAML whitelist. Default is ComfyUI/output; add your own by editing py/config/E_Tier_WL.yaml and restarting.

    The node returns the cleaned text on its text output, and a little web extension pops a read-only preview of what was saved onto the node itself after each run - handy for spotting when a caption got mangled instead of just trusting the file.

    The security stuff, in plain terms

    The README makes a lot of noise about path validation and sanitization, and it's genuinely there: the save directory must already exist (no auto-creation), symlinks are rejected, filenames get forbidden characters replaced and truncate at 100 chars, and the text gets scrubbed of a big list of Python/shell call patterns like eval(, os.system( and friends. Given the custom-node ecosystem's history with malicious nodes, a pack that locks its file writes down is a nice change of pace. Just know the flip side: that sanitizer is a blunt instrument. A caption that legitimately contains something like open( will get bits silently stripped, and you'll only find out from the console print.

    Installing it

    It's a two-second install - no models, no heavy deps, requirements.txt is just pyyaml, which ComfyUI already ships. Via ComfyUI Manager, search "E-Tier-TextSaver". Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/e-tier-newbie/ComfyUI-E-Tier-TextSaver
    

    Then restart ComfyUI. That's it.

    Where people get burned

    • It will not create directories. Point save_to at a folder that exists, or the run fails cleanly with a path error.
    • It overwrites silently. Run the same filename twice and the old caption is gone (it does print "Overwriting existing file" to the console).
    • One token at a time. text_to_remove is a plain substring replace - no regex, no list. If you need to strip <pad> and <eos> both, chain two savers or clean upstream.
    • No subdirectories. Since only the basename survives, you can't write into datasets/part1/ from the filename alone - that's what adding a whitelist entry is for.

    For a one-function node it does exactly what it says, and it's the rare pack where reading the source is reassuring rather than terrifying. If <pad> isn't your problem, you don't need it. If it is, you'll wonder why you hand-stripped tokens for as long as you did.

    CategoryE_Tier/Text

    Inputs (4)

    NameTypeDefaultDescription
    textSTRING
    filenameSTRING
    text_to_removeSTRING<pad>
    save_toCOMBOComfyUI/output1 options: ComfyUI/output

    Outputs (1)

    NameTypeDescription
    textSTRING