Prompt Expansion
The GPT-2 prompt expander that made Fooocus look magic, now a ComfyUI node
- final_prompt
- seed
Ever wonder why the same checkpoint, same prompt, same seed somehow came out better in Fooocus than in ComfyUI? One of the open secrets is this node. PromptExpansion is the Fooocus "V2" style ported into ComfyUI: a small GPT-2 model that reads your positive prompt, and appends a string of quality keywords - extremely lifelike, digital painting, artstation, illustration, concept art, smooth, sharp focus, 8k - that the big image model then actually uses. It's the kind of trick that sounds like marketing until you A/B it, and it's why Fooocus could ship a bare prompt box and still beat A1111 defaults.
What it actually does
This is not an LLM, and the name is a bit of a lie in the best way: it doesn't call any API and needs no key. On your first launch, the node downloads a 343MB model file (fooocus_expansion.bin) from lllyasviel's HuggingFace repo and loads it through the transformers library, locally. That model is a tiny GPT-2 with a vocabulary of a few hundred words - not a chatbot, a keyword generator. Give it your prompt plus a seed, and it samples a suffix like the one above, seeded so the output is reproducible.
The mechanism in the source is worth knowing, because it explains the weird corners. The node tacks , extremely or , intricate, onto your prompt (chosen by your seed's parity - a "magic split" the original Fooocus code used), generates up to 256 tokens, strips out brackets, pipes and colons from whatever came back, and joins the whole thing with commas. That's it. No rewriting, no translation - you get your prompt back plus a quality tail.
The inputs and outputs that matter
- text - your positive prompt, multiline. The one you always set.
- seed - an int, 0 to 4294967295. Drives the expansion: same prompt + same seed = same suffix.
- log_prompt -
No/Yes. Set to Yes and it prints the generated suffix and final prompt to your ComfyUI console. Handy when you're trying to figure out what the model is adding.
Outputs are two: final_prompt (a STRING) and seed (an INT). Wire final_prompt straight into your CLIP Text Encode's positive input, and here's the part people miss - wire the seed output back to your KSampler's seed input. The expansion is seed-dependent, so if you don't, you can fix the sampling seed, change nothing else, and still get a different prompt every run. Keeping them linked is what makes the whole thing reproducible.
Installing it
Easiest route is ComfyUI Manager - search "Prompt Expansion" and hit install. Or, manually:
cd ComfyUI/custom_nodes
git clone https://github.com/meap158/ComfyUI-Prompt-Expansion
Restart ComfyUI. The first launch downloads that 343MB model, so make sure you have internet that one time; after that it's cached. The node needs transformers in your ComfyUI Python environment - ComfyUI usually has it, but if you hit a ModuleNotFoundError: transformers, pip install transformers in the venv you launch ComfyUI with. It appears under the utils category.
Where people get burned
It's an SDXL-era trick, and it shows. The tag-soup suffix was tuned for SDXL's CLIP encoders and works great on Juggernaut-style checkpoints - but for Flux, with its natural-language T5 encoder, appending artstation, 8k can actively fight the model. Keep this node on SDXL/Illustrious-style workflows and skip it for Flux. Also watch the seed default of 0: leave it unconnected and you'll get the same expansion every single run, which defeats the point. Finally, remember what this node is - a quality-suffix appender. It won't fix a badly written prompt; it just fattens a decent one. For that narrow job, it's cheap, local, and surprisingly effective.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | — | |
| seed | INT | 00–4294967295 | — |
| log_prompt | COMBO | No | 2 options: No, Yes |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| final_prompt | STRING | — |
| seed | INT | — |