Nodes/ComfyUI Gemini Nodes/Gemini JSON Extractor
ComfyUI Node

Gemini JSON Extractor

Tell Gemini what fields you want, get JSON back

By jqy-yoΒ·Created about a year agoΒ·Updated 11 months agoΒ· 7
Gemini JSON Extractor
    • extracted_json
    • formatted_output
    β—„promptβ€”β–Ί
    β—„api_keyβ–Ί
    β—„modelgemini-2.0-flashβ–Ί
    β—„extract_fieldstitle: string summary: string keywords: string[]β–Ί
    β—„temperature0.30β–Ί
    β—„seed0β–Ί
    β—„input_textβ–Ί
    β—„system_instructionsExtract the requested information from the provided text. Be accurate and concise.β–Ί

    Extraction without writing a schema

    GeminiStructuredOutput is the powerful route, but sometimes a full JSON Schema is overkill. You just want the model to pull a few named fields out of some text: a title, an author, a list of keywords. That's the whole job of GeminiJSONExtractor - you declare fields in a dead-simple name: type format and it returns clean JSON. It's the middle ground between a free-form text call and a schema-constrained one, and for everyday data wrangling it's often the right amount of tool.

    It lives in the same jqy-yo/comfyui-gemini-nodes pack as the rest of the Gemini nodes and shares their DNA: a prompt, a key, a model, JSON out.

    How it works

    You feed it two things: the text to analyze and a field list. Field definitions use a tiny format:

    title: string
    author: string
    word_count: integer
    tags: string[]
    is_featured: boolean
    category: string?
    

    Supported types are string, number/float, integer/int, boolean/bool, and arrays via type[]. A ? suffix marks the field optional. The node then instructs the model to extract exactly those fields from the input and return them as JSON - the same schema-validation trick as Structured Output, minus the schema-writing ceremony.

    Inputs that matter

    • extract_fields - the field definition block above. This is the heart of the node; get the field names right and the rest takes care of itself.
    • input_text - the text to extract from. Can be combined with the prompt if you want to do both.
    • prompt - extraction instructions. Defaults to "Extract the requested information from the provided text. Be accurate and concise."
    • temperature - default is 0.3, and that's the right instinct: low temperature keeps extraction accurate. Extraction is a task where creativity is your enemy.
    • system_instructions - override the default extraction guidance if you have specific rules (language, format of dates, etc.).

    Outputs are extracted_json (raw JSON - feed it straight into GeminiFieldExtractor or GeminiJSONParser downstream) and formatted_output (a human-readable version with field labels, handy for a preview node).

    Install

    Part of the standard pack install:

    cd ComfyUI/custom_nodes
    git clone https://github.com/jqy-yo/comfyui-gemini-nodes
    cd comfyui-gemini-nodes
    pip install -r requirements.txt
    

    Or grab "ComfyUI Gemini Nodes" via ComfyUI Manager. Key goes in the api_key field or the GOOGLE_API_KEY env var. Restart ComfyUI afterward.

    Where people get burned

    The predictable failure is a field name that doesn't match anything in the text - the model will happily invent a value, so give optional fields the ? suffix and don't demand data that isn't there. Use clear, descriptive field names; "category: string[]" beats "stuff: string[]" every time. And remember this node does cost an API call - it's not a local parser. If the text you're working with is already JSON, you don't need an LLM at all; that's what GeminiJSONParser and GeminiFieldExtractor are for, and they're free. Use this node when the text is messy prose and a regex would be a weekend project.

    CategoryπŸ€– Gemini

    Inputs (8)

    NameTypeDefaultDescription
    promptSTRINGβ€”
    api_keySTRINGβ€”
    modelSTRINGgemini-2.0-flashβ€”
    extract_fieldsSTRINGtitle: string summary: string keywords: string[]β€”
    temperatureFLOAT0.300–1β€”
    seedINT00–2147483647β€”
    input_textoptSTRINGβ€”
    system_instructionsoptSTRINGExtract the requested information from the provided text. Be accurate and concise.β€”

    Outputs (2)

    NameTypeDescription
    extracted_jsonSTRINGβ€”
    formatted_outputSTRINGβ€”