Nodes/ComfyUI-Prompt_util_pack/Prompt Variable Extractor
ComfyUI Node

Prompt Variable Extractor

Pull seed, model, or pose out of a caption

By fmartinellidev·Created 8 months ago·Updated 8 months ago· 0
Prompt Variable Extractor
    • value
    field_name
    variables
    char_to_space
    lowercasefalse

    The README makes the Prompt Variable Extractor sound like a metadata stripper - an input for text, prefix, and delimiter_char, returning cleaned text plus a JSON blob of everything it found. The node that actually ships is dumber and, honestly, handier. It extracts one named variable's value from a text block. That's it. You give it a field name and a variables string, and you get back the value.

    So instead of "clean this caption of all its metadata," think "grab expression out of this caption so I can feed it to another node." It's a tiny regex lookup with three optional post-processing switches, and it pairs with its sibling in the same pack: the Prompt Variable Substitutor puts @key values into a template, this node pulls them out.

    How it works

    Under the hood it runs a case-insensitive search for field_name = 'value' (single quotes, same syntax as the rest of the pack), captures the value, and strips the quote characters. Then three optional transforms kick in, each tied to an input:

    • field_name - the variable you're looking for. expression, seed, model, whatever you tagged in the caption.
    • variables (multiline) - the text to search. This is where you paste your caption or a variable block.
    • char_to_space - if you fill this in, every run of whitespace in the value becomes that character. Put _ here and laughing hard comes out as laughing_hard. Leave it empty to keep spaces.
    • lowercase (boolean) - force the value to lowercase. Great for feeding filenames or filenames-as-tags where case consistency matters.

    Output: a single value string. Nothing else - no JSON, no cleaned copy of the source.

    Where people get burned

    • Empty in, empty out. If field_name or variables is blank, or the field just isn't in the text, you get an empty string. There's no error and no "not found" flag - an empty value is indistinguishable from a real failure. If downstream nodes start misbehaving, check whether value actually resolved.
    • It only knows single quotes. seed="123" won't match. The whole pack lives and dies by key='value'.
    • The field name is exact-ish. The match is case-insensitive, but expression will not match expressions. Type the key exactly as it appears.

    Why you'd reach for it

    Real use case: you're building a batch-generation setup where each prompt carries metadata - #seed=1234, #model='epicrealismxl', #expression='smiling' - and you want one of those values as a value, not as prompt text. Extract seed and feed it into a seed node so the same seed re-renders a run; extract expression and drop it into a filename. It's the kind of plumbing that turns "keep this number in sync across three nodes by hand" into "let the graph read it from the caption."

    Installation

    It ships in the four-node Prompt util pack, pure Python with zero external dependencies - no requirements.txt, no model files.

    cd ComfyUI/custom_nodes
    git clone https://github.com/fmartinellidev/ComfyUI-Prompt_util_pack
    

    Restart ComfyUI (or search "Prompt_util_pack" in ComfyUI Manager). Fair warning: the README documents a different API than the shipped code. Trust what the node's inputs actually are - field_name, variables, char_to_space, lowercase - not the text/prefix/delimiter_char the README describes. The README has drifted; the code hasn't moved.

    Categoryprompt/util_pack

    Inputs (4)

    NameTypeDefaultDescription
    field_nameSTRING
    variablesSTRING
    char_to_spaceSTRING
    lowercaseBOOLEANfalse

    Outputs (1)

    NameTypeDescription
    valueSTRING