Nodes/ComfyUI Prompt Template/MIM Prompt Template Json
ComfyUI Node

MIM Prompt Template Json

The *var template node that substitutes AND encodes for you

By DaniilVdovin·Created 11 months ago·Updated 11 months ago· 1
MIM Prompt Template Json
  • clip
  • positive
  • negative
  • positive
  • negative
  • json
template_positiveA *obj on a *place
template_negative
variables_json{"obj": "cat", "place": "table"}

Write your prompt once with *obj and *style style placeholders, drop a JSON object of values in, and this node does two jobs at once: it swaps the variables in, and it encodes the finished prompt straight into conditioning. So instead of "here's a template, go find a text node to render it", you get a node that sits between your templates and the KSampler and just works. It's the anchor of the ComfyUI Prompt Template pack from DaniilVdovin, and the other nodes in the pack are basically variations on this one.

Why reach for it? Two reasons. Reuse - one template, swap the JSON, get a different image without touching the prompt grammar. And variety - the README's selling point is that you can chain several of these, so one set of keys fans out into many different rendered prompts (same key, different values; different keys, same value; that whole cartesian game). If you're coming from the wildcard/bracket-trick school of prompt randomization, this is the structured version: instead of {a|b|c} inline, you keep the variation in one place.

How it works

The mechanism is refreshingly simple: it json.loads your variables_json, then does a plain .replace() on the template for each *key. Whatever the value is gets inserted as literal text. If a clip is connected, the node tokenizes and encodes both resolved prompts into CONDITIONING. If not, it still runs - which turns out to be useful (see below).

The inputs that matter

  • template_positive - your template with *obj, *place, etc. (default A *obj on a *place).
  • template_negative - same syntax, for the negative.
  • variables_json - the values, e.g. {"obj": "cat", "place": "table"}.
  • clip - optional, but connect it unless you specifically want text-only.

Outputs: positive and negative CONDITIONING (wire into the KSampler), then positive and negative STRING (the resolved raw prompts - handy for a preview text node or to feed another template), plus a json STRING that echoes your variables back out for chaining.

Installing

No dependencies at all - the pack is pure Python stdlib, no requirements file, no models to fetch. Manager route: search "ComfyUI Prompt Template". Or:

cd ComfyUI/custom_nodes
git clone https://github.com/DaniilVdovin/ComfyUI-prompt-templating.git

Then restart ComfyUI.

Where people get burned

  • Malformed JSON fails silently. A missing brace means variables = {} and your *obj stays literally in the prompt - no error, no warning, just a prompt that suddenly has asterisks in it. If you see a stray * in your render, check the JSON first.
  • Variable names are prefix-sensitive. Replacement is a naive .replace(), so if you have *obj and *obj2, resolving *obj first mangles *obj2 (it becomes <value>2). Keep names distinct, like *subject and *background.
  • Disconnect clip only on purpose. With no clip the conditioning outputs are degenerate, so use this as a text-only node (the STRING outputs) or leave clip attached.
  • *var and {a|b|c} stack. The template fields are flagged dynamicPrompts, so with ComfyUI's Dynamic Prompts toggle on you can combine bracket randomization with your substitutions - one node doing both layers of variety.
CategoryMIM_Prompts

Inputs (4)

NameTypeDefaultDescription
clipoptCLIP
template_positiveoptSTRINGA *obj on a *place
template_negativeoptSTRING
variables_jsonoptSTRING{"obj": "cat", "place": "table"}

Outputs (5)

NameTypeDescription
positiveCONDITIONING
negativeCONDITIONING
positiveSTRING
negativeSTRING
jsonSTRING