Folder Image and Extract Prompt
Pull the prompt back out of every image in a folder — your dataset just got easier
- images
- prompts
Every image you generate in ComfyUI has its prompt baked into its PNG metadata. Most people never touch that data again. FolderImageAndExtractPrompt is the node that reaches back in, pulls the prompt out of every image in a folder, and hands it to you as a list - images in one hand, their prompts in the other.
If that sounds like the start of a captioning pipeline, you're right. This is a dataset-prep node dressed in loader clothing. Instead of re-captioning hundreds of images from scratch for a training run, you can extract the prompts that actually generated them and use those as your captions - with the caveat that "what generated it" and "what you want to train" are often different, a gap worth respecting when you curate (the lora-training doc has opinions on caption quality, and it's right).
How it works
The node scans the folder, opens each image, and reads its PNG metadata. It understands two formats: ComfyUI's own prompt metadata (a JSON graph) and A1111/WebUI's parameters string. For ComfyUI images, it walks the embedded graph, finds sampler-like nodes, and follows their positive-conditioning link to reconstruct the main positive prompt. That's the clever part - it's not just dumping raw JSON at you, it's actually extracting the prompt string from the graph topology.
The heuristic isn't perfect. It's looking for node class names containing "Sampler", "KSampler", "Guider", and similar, then tracing the positive input. If your workflow routes conditioning through custom nodes with weird names, the extraction can come back empty - that's not a bug, it's the limit of pattern matching on an arbitrary graph.
Inputs and outputs
One input: directory - the path to your folder of images. No picker, so type carefully.
Two outputs, both lists:
images- the images themselves, ready to feed a batch chain.prompts- one prompt string per image, in matching order.
Because the two lists are index-aligned, you can zip them together downstream - send images one way for processing and prompts to a text encoder or a dataset writer.
Installing it
Part of the AnotherUtils pack:
cd ComfyUI/custom_nodes
git clone https://github.com/marcoc2/ComfyUI-AnotherUtils.git
Restart ComfyUI, or install via ComfyUI Manager by searching "AnotherUtils". No model downloads and no extra Python dependencies - this one is pure metadata reading.
Where it falls over
Two realistic failure modes. First, non-ComfyUI images (screenshots, downloads, images from other tools without proper metadata) will return empty strings - there's nothing in the file to extract, and the node has no fallback captioner. Second, images that were generated but with a prompt you've long since changed: you get the old prompt back, which may not match the image's style at all if you've been tuning.
So treat this as an extraction tool, not a captioning oracle. For a folder you generated with a consistent workflow, it's a massive time-saver. For a grab-bag of strangers' images, you'll still be captioning by hand. The "folder metadata by node name" sibling in this pack does a similar trick keyed to specific nodes if you need more control.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| directory | STRING | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| images | IMAGE | — |
| prompts | STRING | — |