Nodes/VLM_nodes/Text Template
ComfyUI Node Runs on cloud

Text Template

Text Template

By gokayfem·Created 3 years ago·Updated 9 days ago· 583
Text Template
    • text
    • variables_json
    • missing_keys_json
    template{instruction} Context: {text1}
    variables_json{"instruction":"Describe the input accurately."}
    missing_valuesError
    text1
    text2
    text3
    text4

    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."}
    • text1text4 - 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 the Error case 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.

    CategoryVLM Nodes/Text/Create

    Inputs (7)

    NameTypeDefaultDescription
    templateSTRING{instruction} Context: {text1}
    variables_jsonSTRING{"instruction":"Describe the input accurately."}
    missing_valuesCOMBOError3 options: Keep placeholder, Empty string, Error
    text1optSTRING
    text2optSTRING
    text3optSTRING
    text4optSTRING

    Outputs (3)

    NameTypeDescription
    textSTRING
    variables_jsonSTRING
    missing_keys_jsonSTRING