Text Template
Text Template
- text
- variables_json
- missing_keys_json
Templating is how you stop rewriting prompts by hand, and VLMTextTemplate is the pack's safe version of it. You write a template with {named} placeholders, supply values from a JSON object, and it renders the final string - with the twist that missing values are handled explicitly instead of silently. No more "why does my prompt have a literal {label} in it?" debugging sessions.
The template is rendered from two sources: a variables_json object for arbitrary named placeholders, and four dedicated live text sockets - text1 through text4 - for the values you want wired in from other nodes rather than typed into JSON. It's the difference between "prompt as data" and "prompt as wiring," and you usually want a mix.
How it works
Your template is a plain multiline string: "Describe {object} in the {context}.". Placeholders are named - no Python attribute/index expressions, no eval - which is a deliberate safety decision: the template engine never evaluates code, never follows references, and never touches files or the network. What you see is what gets substituted.
Values come from:
variables_json- a JSON object whose keys are placeholder names. Default example:{"instruction":"Describe the input accurately."}text1…text4- convenient live sockets mapped to{text1}…{text4}placeholders. Wire a node's output here and reference it in the template without touching JSON.
Then the important part: missing_values policy, one of three:
Keep placeholder- leave{name}in the output (good for partial templates).Empty string- render missing as empty.Error(default) - fail the node loudly so you find out immediately that a variable never got supplied.
Error is the right default for automation. A template that renders with a hole in it is a prompt you'll discover is broken two queues later; a template that fails instantly is a bug you fix in thirty seconds.
Outputs
text- the rendered result.variables_json- the values actually used, echoed back for inspection.missing_keys_json- the keys that were referenced but missing, which makes theErrorcase diagnosable instead of opaque.
Install
Part of ComfyUI VLM Nodes (gokayfem/ComfyUI_VLM_nodes). ComfyUI Manager → search "VLM Nodes", or:
cd ComfyUI/custom_nodes
git clone https://github.com/gokayfem/ComfyUI_VLM_nodes
python -m pip install -r ComfyUI/custom_nodes/ComfyUI_VLM_nodes/requirements.txt
Run with ComfyUI's Python; the repo won't touch torch. Pure string rendering, no models, no downloads.
Gotchas
The template field is direct-name substitution - {a.b} or {a[0]} style expressions are not supported, and that's on purpose. If you need nested JSON lookups, pre-process with VLMJSONExtract and feed the result in as a named variable or a text socket. And keep an eye on the missing_values default: if you're building a template where a variable is sometimes absent by design, switch the policy to Keep placeholder or Empty string rather than letting it error on you every other run.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| template | STRING | {instruction} Context: {text1} | — |
| variables_json | STRING | {"instruction":"Describe the input accurately."} | — |
| missing_values | COMBO | Error | 3 options: Keep placeholder, Empty string, Error |
| text1opt | STRING | — | |
| text2opt | STRING | — | |
| text3opt | STRING | — | |
| text4opt | STRING | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| text | STRING | — |
| variables_json | STRING | — |
| missing_keys_json | STRING | — |