AI2Go Prompt Batch
ComfyUI has no for-loop — this node fakes one for your prompts
- positive
- negative
- index
ComfyUI doesn't have a real for-loop. The classic workaround for "generate the same image with twenty different prompts" is the Load Image Batch + increment index trick: queue N runs by hand and let a counter walk a list. This node is the text analog. Paste in a JSON list of prompts, queue N runs, and each run emits one prompt from the list. It won't change your life if you generate one image at a time - it absolutely will if you've ever sat there queueing the same graph ten times to test variations.
How it works
The prompt list lives in a hidden prompts_json field that's the source of truth, kept in sync with a row editor on the node itself. Each row is a positive and negative text box side by side; ➕ Add Prompt appends a row, 🗑 removes one, and the ⠿ handle drag-reorders. The node auto-grows and auto-shrinks to fit. An index counter picks which prompt fires this run, and the front-end advances it by 1 after each queued run - so a queued batch walks 0, 1, 2… down the list. It's deliberately immune to the "Widget Value Control Mode" setting, which is a classic ComfyUI footgun that quietly freezes widget state mid-batch.
The practical loop looks like this:
- Build your list in the rows editor.
- Click 🔍 Check for prompts - it validates, counts N, and resets the index to 0.
- Set ComfyUI's queue count to N and run.
Two toggles worth knowing: reset_index_at_batch_start (on by default) zeroes the index when a new batch is queued so every batch starts from the first prompt, and delete_empty_prompts (on by default) drops blank rows so they never break a run or skew your count.
The JSON
Each entry is an object with a required positive and optional negative:
[
{ "positive": "a red fox in the snow, highly detailed, 8k", "negative": "blurry, watermark" },
{ "positive": "a neon-lit city street at night, cinematic" }
]
The importer is forgiving: a bare string counts as positive-only (["a red fox", "a neon city"]), prompt works as an alias for positive, and the array can be wrapped as { "prompts": [ ... ] }. There's also a json_in STRING socket - wire a text/primitive node holding a JSON list here, click 📥 Read from JSON, and it appends into your rows. Note the socket is ignored at run time: the rows you edit are what actually run.
The outputs
positive and negative - feed them into your CLIP text encode. Plus index, the 0-based index used this run. Wire that into a SaveImage filename and each output file records which prompt made it. That detail is also why this node pairs well with the pack's AI2Go Save Metadata (Civitai) nodes - their trace reads the batch node's current index and resolves the exact line that ran, so the PNG metadata matches the image.
Gotchas
- Overshoot the list (queue more runs than prompts) and the index clamps to the last prompt instead of erroring - arguably right, but worth knowing so you don't silently regenerate your final prompt N times.
- With
delete_empty_promptsoff, an emptypositiveraises a "positive is empty" error at run time. Leave it on.
Install
cd ComfyUI/custom_nodes
git clone https://github.com/Little-God1983/ComfyUI-AI2Go-Utils
Restart ComfyUI. Pillow is the only dependency, no model downloads. And the usual pack disclaimer: published for reference, issues disabled, GPL-3.0 - you can fork it, you just can't expect the author to hold your hand.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| prompts_json | STRING | [ { "positive": "a red fox in the snow, highly detailed, 8k", "negative": "blurry, watermark" }, { "positive": "a neon-lit city street at night, cinematic", "negative": "" } ] | Authoritative prompt list as JSON. Hidden in the UI and kept in sync with the row editor by the front-end — edit the rows, not this. |
| index | INT | 00–1000000 | Which prompt to emit this run (0-based). The front-end advances it by 1 after each queued run so the batch walks the list. "Check for prompts" resets it to 0. |
| reset_index_at_batch_start | BOOLEAN | true | When on, the index is reset to 0 at the start of every queued batch, so each batch starts from the first prompt. Off = the index keeps its value between batches. |
| delete_empty_prompts | BOOLEAN | true | When on, prompts with an empty 'positive' are dropped when you press "Check for prompts" and just before a batch is queued, so blank rows never break a run or throw off the count. |
| json_inopt | STRING | Optional STRING socket. Wire a text/primitive node holding a JSON prompt list here, then press "Read from JSON" to import it into the rows. Ignored at run time — the rows you edit are what actually run. |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| positive | STRING | — |
| negative | STRING | — |
| index | INT | — |