Save String (Swwan)
Dump the prompt that made that image to a .txt
- filename
ComfyUI is only half a notes app. A PNG carries the graph, which is great, but there are times you want the text separate: a caption for a training image, a running log of prompts and settings, a sidecar your script can read without a PNG parser. Save String takes one STRING and writes it to a file. That's the whole node, and it's more useful than it sounds.
Two real uses. The first is training sets: the dataset convention is pairs of files sharing a basename - 0001.png next to 0001.txt - because every trainer (kohya, ai-toolkit, OneTrainer) walks a folder and reads the caption from the text file rather than from inside the image. The second is bookkeeping: wire a prompt, a seed, or a JOIN-assembled summary in here and you get a plain-text record of what the run actually used, which survives you deleting the image by accident.
How it works
You give it a string, a filename_prefix, an output_folder and a file extension, and it writes {prefix}_{counter:05}{extension} into the resolved folder. Relative output_folder values are resolved against ComfyUI's base directory when the host sets one, and the default of output lands you in ComfyUI's output directory; an absolute path is used as-is and created if missing. The counter comes from ComfyUI's save-path resolver, so numbering is per-folder and it won't clobber an existing file.
One source-level quirk worth knowing, because it will confuse you otherwise: the node declares a filename STRING output, but the shipped implementation returns an empty result list. The write happens - the file is on disk, and this is a terminal output node so it always runs - but the filename socket hands back nothing useful. Don't build a downstream branch on it; if you need the path, use Save Image (Swwan), which returns absolute paths properly.
Note also that string is declared forceInput, so it renders as a socket rather than a text box. You cannot type into this node. Wire a text primitive, a prompt node, or a string-producing node into it.
Inputs and outputs
Required: string (the author's tooltip: "string to save as .txt file", wire-only), filename_prefix (default text, supports ComfyUI's templating such as %date:yyyy-MM-dd%), output_folder (default output). Optional: file_extension (default .txt - the tooltip calls it the caption extension, which is the intended use). Output: filename (STRING), which as noted comes back empty in practice.
Install
Ships with the pack - and this one has no replacement recommended, so it's the current entry point rather than a legacy shim:
cd /path/to/ComfyUI/custom_nodes
git clone https://github.com/aining2022/ComfyUI_Swwan.git
cd ComfyUI_Swwan
python -m pip install -r requirements.txt
Python 3.11+; the pack's requirements.txt installs numpy, Pillow, opencv-python, scipy and scikit-image while torch/torchvision come from your ComfyUI environment. Writing a text file needs none of that, but the pack loads as a unit. Restart, refresh, search Swwan.
Where people get burned
Text nodes don't run on their own. It's an output node, so it executes when you queue - but only if the graph reaches it. A bypassed or muted branch that feeds the string means no file, which reads as "the node is broken."
Where did it go? output_folder defaults to output, so files land in ComfyUI/output/ next to your images, not in a subfolder. Change the prefix (%date:yyyy-MM-dd%) if you want them grouped by day.
Pairs, not guesses. If you're writing captions for training, the basename has to match the image exactly - foo_00001.txt next to foo_00001.png. Two savers with different prefixes give you a folder full of orphaned captions. And if you'd rather have the caption written by the image saver in one go, the pack's legacy Save Image (Swwan) · 旧版兼容 has a caption input and caption_file_extension for exactly that.
Non-ASCII. The file is opened with your platform's default text encoding - UTF-8 on Linux and macOS, often cp1252 on Windows. If a caption with accented characters or CJK comes back mangled in another tool, that encoding mismatch is the first suspect.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| string | STRING | string to save as .txt file | |
| filename_prefix | STRING | text | The prefix for the file to save. This may include formatting information such as %date:yyyy-MM-dd% or %Empty Latent Image.width% to include values from nodes. |
| output_folder | STRING | output | The folder to save the images to. |
| file_extensionopt | STRING | .txt | The extension for the caption file. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| filename | STRING | — |