ComfyUI Node

D2 Prompt

A prompt box that eats your comments and counts your tokens

By da2el-ai·Created 2 years ago·Updated 5 days ago· 66
D2 Prompt
    • text
    prompt
    comment_type
    insert_lora
    token_countfalse

    You know what's annoying? Keeping multiple prompt variants in one workflow and having to comment out the ones you're not using, then cleaning up the // marks before the sampler chokes on them. D2 Prompt is a text node built for exactly that workflow: it strips comments from your prompt before it goes anywhere, and it can show you the token count as you type. It's a small quality-of-life node, but if you maintain several prompt versions in one graph, it quietly becomes essential.

    How it works

    The node is a multiline prompt box with a comment_type dropdown: # + // + /**/ (the catch-all), or # only, // only, /* */ only, and None. Whatever comment syntax you choose gets deleted from the text before the text output. So you can write a prompt with several candidate lines, comment out the losers with //, and the node sends only the active version downstream. No more manually editing prompt strings before each run.

    The other trick is the token_count toggle. Flip it on and the node shows a live token counter in the widget - the pack counts tokens via its own endpoint, so you get a CLIP-token-style estimate right in the node rather than guessing whether your prompt is about to get truncated. Set token_count to false when you're done tuning and the widget goes back to being a plain box.

    There's also an insert_lora dropdown listing your LoRAs - pick one and it inserts the reference at the cursor position, in the <lora:name:strength> format that D2 KSampler understands. Convenient, though if you're managing several LoRAs you'll probably use the dedicated D2 Load Lora node instead.

    Inputs

    • prompt - the multiline text.
    • comment_type - which comment syntax(es) to strip. Pick the one matching how you write comments.
    • insert_lora - dropdown to insert a LoRA reference.
    • token_count - on/off live token display.

    One output: text, the comment-stripped prompt. Wire it into D2 KSampler's positive (or negative) and you're done - no CLIP encode node needed in between.

    Where it fits

    The obvious use is the "one workflow, N prompt variants" pattern: keep them all in the box, comment out the ones you're not running. It also composes well with D2 Regex Replace downstream - strip comments here, then normalize tags before the sampler. And because the output is just a plain string, you can tee it into an XY plot's x_list if you want to grid-compare the variants you've been toggling.

    Installing

    Part of D2 Nodes ComfyUI:

    cd ComfyUI/custom_nodes
    git clone https://github.com/da2el-ai/D2-nodes-ComfyUI
    

    or search "D2 Nodes ComfyUI" in ComfyUI Manager.

    Two things to know before you rely on it: first, the comment stripping is the whole job - if you set comment_type to None, nothing is removed, so double-check the dropdown if your output still contains //. Second, the token count is an estimate from the pack's own counter, not the exact CLIP tokenizer every model uses - treat it as "is this way too long," not as a precise science. For the precise number you'd still verify against your actual model, but as a tripwire it's miles better than nothing.

    CategoryD2/Text

    Inputs (4)

    NameTypeDefaultDescription
    promptSTRING
    comment_typeCOMBO5 options: # + // + /**/, # only, // only, /* */ only, None
    insert_loraCOMBO1 options: CHOOSE
    token_countBOOLEANfalse

    Outputs (1)

    NameTypeDescription
    textSTRING