Nodes/ComfyUI-northTools/Extract Metadata value by key
ComfyUI Node

Extract Metadata value by key

Pull the prompt out of that image metadata string

By northumber·Created about a year ago·Updated about a year ago· 4
Extract Metadata value by key
    • value
    metadata
    key

    ComfyUI has a culture of embedding the workflow in the PNG - drag an image back in and the whole pipeline reconstructs. That culture is also a data source: every generated image carries a metadata blob, and if you're batch-processing folders you'll eventually want one specific field out of it. This node is the one-liner for that: give it a metadata string and a key, get the value back.

    It was built to sit right after the pack's LoadImagesFromDirList, whose METADATA output is a stringified Python dict of the image's PNG text chunks plus EXIF. Wire that output in here, type prompt (or workflow, or whatever key you're after), and out comes just that value.

    How it works

    The mechanism is small but slightly clever about parsing. It first tries ast.literal_eval on the metadata string - that handles the Python-dict format the loader produces, complete with single quotes. If that fails it falls back to swapping single quotes for double and running json.loads. Either way it then reads the requested key from the resulting dict and returns the value as a string, stripping surrounding quotes and unescaping any \n or \u sequences along the way. If neither parser works, you get back an empty string rather than an error - so a corrupt metadata blob doesn't crash the workflow, it just yields nothing.

    Two required inputs, both plain strings:

    • metadata - the metadata blob. Source it from LoadImagesFromDirList's METADATA output, or paste any metadata text in.
    • key - the field to extract. ComfyUI's own embedded metadata has keys like prompt and workflow; for general PNGs you might pull Software, Model, or whatever the generating tool wrote. Leave it empty and the node returns the whole parsed dict as a string, which is a handy debug move.

    The single output is value.

    Where it fits

    The obvious pairing is the one the pack was designed around: batch-load a folder with LoadImagesFromDirList, run the metadata through this node keyed on prompt, and you've got every source prompt as a string - ready for a comparison node, a log, or a "did the prompt survive the round-trip" check. It also works fine as a general PNG-inspector when you have metadata text from elsewhere and want one field without a whole metadata viewer node.

    Install

    Manager → search "ComfyUI-northTools", or git clone https://github.com/northumber/ComfyUI-northTools into custom_nodes, then restart. No models, no extra dependencies beyond what ComfyUI already ships.

    The honest caveat

    It's a small parser, not a metadata explorer. If the key doesn't exist in the dict you silently get an empty string - no error telling you the key is wrong, just nothing. That's fine once you know the key names in your images, but expect a little trial and error the first time: type the key, see what comes back, adjust. For a one-key-at-a-time extractor it does the job, and it's the right weight for the pack it ships in.

    CategorynorthTools

    Inputs (2)

    NameTypeDefaultDescription
    metadataSTRING
    keySTRING

    Outputs (1)

    NameTypeDescription
    valueSTRING