ComfyUI Node

HT Dynamic Prompt

Wildcard prompts that stop before the token limit

By ArtHommage·Created 2 years ago·Updated about a year ago· 4
HT Dynamic Prompt
  • clip
  • prompt
  • token_info
  • clip
text
seed0
autorefreshNo
strip_whitespaceNo
max_tokens75

If you've used A1111's dynamic prompts or the comfyui-dynamicprompts extension, you know the drill: write a template with {option|option} variations and __wildcards__ that pull from text files, and every generation rolls a fresh prompt. HT Dynamic Prompt, from HommageTools, does that inside the pack - with the genuinely useful addition of real token counting, so a template that expands too big gets caught before it hits the CLIP's 77-token wall instead of after.

How it works

It uses the dynamicprompts library under the hood (which is why that package is in the pack's requirements). You give it a template and a seed; it expands the syntax into a concrete prompt.

Inputs:

  • text - the template, supporting {a|b|c} alternatives and __wildcard__ references.
  • seed - makes the expansion reproducible. Same template + same seed = same prompt, every time.
  • autorefresh (Yes/No) - refresh the output every time the node evaluates, versus only when something upstream changes. Keep it on "Yes" for batch exploration.
  • strip_whitespace (Yes/No) - collapse excess whitespace and linebreaks in the result. Worth enabling when you're pasting into a one-line CLIP encoder.
  • max_tokens (default 75) - the cap. The node truncates the expanded prompt to stay under it.
  • clip (optional) - plug in your CLIP and it counts tokens with the actual text encoder instead of a rough heuristic. The author's tooltip spells out why: "to avoid token limit errors."

Outputs:

  • prompt - the expanded STRING, ready for CLIP Text Encode.
  • token_info - a text readout of the token count, handy for debugging.
  • clip - passes your CLIP through if you connected one.

The smart part

Token truncation instead of failure is the differentiator. Wildcard combos are combinatorial - a template with three {a|b|c|d} slots has 64 expansions, and a few of them will be long. Most dynamic prompt nodes just throw the long one at CLIP and let it error or silently truncate. This one counts first and trims the expansion to fit max_tokens, which is the difference between a batch job that runs to completion and one that dies on frame 47.

Where it fits

Batch prompt exploration is the whole game: a template with randomized subjects, styles, and camera angles, run across N seeds, gives you a varied contact sheet without writing each prompt by hand. Pair the prompt output with your CLIP encoder and keep seed wired to a seed generator so each run is different but reproducible.

Installing it

Ships with HommageTools, and needs the dynamicprompts pip package (in the pack's requirements). ComfyUI Manager → search HommageTools, or:

cd ComfyUI/custom_nodes
git clone https://github.com/ArtHommage/HommageTools.git
cd HommageTools && pip install -r requirements.txt

Restart ComfyUI.

Gotchas

  • Wildcard files are looked up in a wildcards folder (ComfyUI base, then the comfyui-dynamicprompts custom node folder). If your __wildcard__ comes back literal and unexpanded, the file isn't where it's looking - that's the first thing to check.
  • max_tokens counts tokens, not characters. 75 is a safe default under the 77-token limit; if you have your own CLIP variant with a different ceiling, set it accordingly.
  • LoRA tags (<lora:...>) are stripped before counting so they don't eat your token budget.

For template-driven batch generation, this is one of the more complete dynamic prompt nodes around - and the token guard alone justifies trying it.

CategoryHommageTools

Inputs (6)

NameTypeDefaultDescription
textSTRING
seedINT00–18446744073709550000
autorefreshCOMBONoAutomatically refresh the output on node evaluation
strip_whitespaceCOMBONoRemove excessive whitespace and linebreaks
max_tokensINT7510–1000Maximum number of tokens in the output prompt (to avoid token limit errors)
clipoptCLIPCLIP model for accurate token counting

Outputs (3)

NameTypeDescription
promptSTRING
token_infoSTRING
clipCLIP