π¦ Bulk Prompt Ollama Improver
A local LLM that improves every prompt in your batch β without the chat-scaffolding garbage
- result
- context
- meta
Wire a Bulk Prompt Loader into this node and every prompt in your batch gets rewritten by a local Ollama model before it ever reaches a CLIP Text Encode. That's the whole job, and it's a good one: you feed it a rough idea like "a red apple on a wooden table" and it hands back a more vivid, detailed version, offline, uncensored, free per call. The reason to care about this node specifically is that it solves the one problem that sinks every other prompt-enhancer: chat models love to wrap their answers in "Sure! Here's an improved version:" and markdown fences, and that scaffolding lands in your conditioning as literal prompt tokens if nobody strips it.
How it works
It uses the official ollama Python library against a running Ollama server - so Ollama is a separate process, not something loaded in-graph. Each run calls generate() with your prompt, your instruction as the system prompt, and a keep_alive value. The node is version-tolerant across ollama-python 0.4β0.6 and declares VALIDATE_INPUTS, so the dynamically-fetched model list passes ComfyUI's backend validation instead of throwing the classic "unknown required inputs" error on load.
The star is trim_output (on by default). After the model replies, the node runs a real cleaning pass: leading preambles, --- rules, ``` code fences, Prompt: headers, surrounding quotes, and trailing "let me know if you'd like changes!" offers all get stripped, leaving just the prompt. The KB's writeup on local-LLM prompting calls dirty output the #1 failure mode of this category of node - a model's conversational habits bleeding into your conditioning is worse than no enhancer at all. This node bakes the fix in. Turn trim_output off and you get the raw reply if you want to see what the model really said.
Inputs and outputs
Set these and forget them:
- url - default
http://127.0.0.1:11434. Change it for a remote host (http://192.168.1.50:11434), then hit π Reconnect to refresh the model dropdown. - model - populated by clicking Reconnect. Pick the one you
ollama pull'd. - instruction - the system prompt telling the model what to do. The default ("Rewrite the following prompt to be more vivid and detailed. Output ONLY the improved prompt...") is genuinely good; tighten it if you want a specific style.
- timeout - default 120 seconds. Bump to 300+ for big models (14B+), because the first call also has to load the model into VRAM and that counts against the budget.
- keep_alive_minutes - how long Ollama keeps the model resident after a call.
-1keeps it forever,0unloads immediately. If you're batch-running hundreds of prompts, this is the difference between fast and "waiting for a model load every row." - enabled - flip off to pass prompts through unchanged, no Ollama call. Cheap A/B toggle.
Optional context input accepts comma-separated ints for multi-turn continuity. Outputs: result (the improved, trimmed prompt - wire it to your CLIP Text Encode), context (Ollama's context tokens, for chaining), and meta (JSON with the model, timing, token counts, and a trimmed flag - handy if you want to see how long the rewrite actually took).
Installing it
The one node in the pack with a dependency. The pack's requirements.txt pins ollama>=0.4.0; ComfyUI Manager will install it automatically, or do it yourself:
cd ComfyUI/custom_nodes
git clone https://github.com/sifatrads/comfyui-bulk-prompt.git
pip install ollama
Then make sure Ollama is running (ollama serve) and pull a model, e.g. ollama pull qwen2.5:7b or llama3.1. The pack's __init__.py is defensive here: if the ollama package is missing, this node is silently disabled but the core loader nodes keep working - so a missing import won't take down your whole batch setup.
Where people get burned
- Timeouts on the first few rows - that's the model loading into VRAM. Raise
timeout, or setkeep_alive_minutesto-1so it stays warm. - Model dropdown is empty / "No Ollama model selected." - click π Reconnect. The list is cached; pulling a new model in the terminal won't show up until you refresh.
- Ollama on a different machine - you can point
urlanywhere reachable, and the node normalizes a barelocalhost:11434to a proper URL for you. - VRAM - you're now budgeting for two models at once (LLM + checkpoint). Keep the LLM small (an 8B, or 3B on tight cards) and lean on
keep_aliveso it doesn't sit resident when you're not batching. The KB's guidance is blunt: the job doesn't need a big reasoning model, it needs a small obedient one that follows a format and stops.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| instruction | STRING | You are an expert prompt engineer for image generation. Rewrite the following prompt to be more vivid and detailed. Output ONLY the improved prompt, with no preamble or explanation. | System prompt β tell the model what to do with the prompt. |
| url | STRING | http://127.0.0.1:11434 | Ollama server URL. Change this for a custom host/port (e.g. http://192.168.1.50:11434), then click π Reconnect. |
| model | COMBO | Pick a model (auto-loaded from the Ollama server at the default URL). After changing url or pulling new models, click π Reconnect to refresh the list. | |
| keep_alive_minutes | INT | 5-1β1440 | Minutes Ollama keeps the model loaded after inference (-1 = keep forever, 0 = unload immediately). |
| timeout | INT | 1205β3600 | Max seconds to wait for the response. Large models (e.g. 14B) need more β the first run also loads the model into VRAM. Use 300+ if you hit timeouts. |
| enabled | BOOLEAN | true | If off, the prompt passes through unchanged (no Ollama call). |
| trim_output | BOOLEAN | true | Keep only the prompt: strip any chat wrapper the model adds (preambles, '---'/code-fence/'Prompt:' headers, trailing offers). Turn off to use the raw reply. |
| positive | STRING | β | |
| contextopt | STRING | Optional Ollama context (comma-separated ints) for multi-turn continuity. |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| result | STRING | β |
| context | STRING | β |
| meta | STRING | β |