Nodes/ComfyUI Gemini Expanded API/Configure Gemini Response Schema
ComfyUI Node

Configure Gemini Response Schema

Gemini Answers in Prose Unless You Hand It a Schema First

By silveroxides·Created about a year ago·Updated 2 days ago· 5
Configure Gemini Response Schema
  • schema_state
  • schema
  • schema_json

You ask Gemini for a caption, a batch of tags, a shot list, a structured prompt for the sampler - and you get a chatty paragraph back. "Sure! Here's a description of the image: ..." All of that lands in your downstream text node and garbage-flows into the conditioning. This node is how you stop that: you define the shape of the answer you want, and Gemini is obliged to return JSON in that shape instead.

Worth knowing up front: this node calls nothing. It needs no API key, no network, and no proxy. It's a form. You fill it in, it hands a JSON Schema to the node that actually does the talking.

How it works

Under the hood this is a standard JSON Schema authored through a visual editor. The node carries exactly one input, schema_state, and you never wire anything to it - it's a socketless widget holding a serialized tree of your fields (version, root, next_id, entries). Every field you add with Add field is an entry in that tree with a type, a name, a required flag, a description, and its own children.

When you queue the node it compiles your tree into a real schema dictionary and emits two things. On the receiving end, Expanded Gemini Text/Image takes that schema and sets the request's MIME type to application/json with the schema attached, so the model is constrained at generation time rather than asked politely. The final text is then parsed with a strict JSON parse - invalid JSON is reported as a processing error, not quietly repaired or retried.

The field types are Object (a group of named fields), Array (a list holding one item definition), Text, Integer, Number, and Boolean. Text can be Any text or From list, where one allowed answer per line becomes a real enum. Integer and Number take optional bounds. Boolean tells the model to reply true or false - it doesn't pre-set the answer.

The inputs and outputs that matter

schema_state is the only input, and it's the editor itself. The two outputs:

  • schema - wire this into the Response format input on Expanded Gemini Text/Image. That input sits after video and just before the image autogrow slots. Leave it unplugged and you get a normal, unconstrained answer.
  • schema_json - the same schema as a pretty-printed string. Handy for Preview as Text when you want to eyeball what you built, or for anything downstream that wants text.

Names are trimmed and have to be nonempty and unique among enabled siblings, or the node errors at queue time. Disabled hides a field while keeping its settings; Remove deletes it and everything nested inside. Type changes retain the inactive settings, so switching a group to a Text and back doesn't destroy your work.

One honest limitation, and it's Gemini's not the node's: the parse checks JSON syntax, not factual correctness or full schema compliance. A model that returns valid JSON with the wrong values is still "valid".

Installing it

Through ComfyUI Manager, search ComfyUI Gemini Expanded API. Manually:

cd ComfyUI/custom_nodes
git clone https://github.com/silveroxides/ComfyUI_Gemini_Expanded_API.git
cd ComfyUI_Gemini_Expanded_API
pip install -r requirements.txt   # google-genai>=2.17.0, numpy, torch, Pillow

Then restart. Nothing here downloads a model file; the heavy dependency is google-genai, installed once and shared with the rest of the pack.

Last word on trust: this pack holds your Google key and makes outbound calls by design, so it's the category where reading before installing pays off. For what it's worth, the author is a known name - silveroxides on Hugging Face publishes the Chroma GGUF quants people actually download. But the pack itself is obscure; there are no Reddit threads about it, so don't expect a crowd to have hit your bug first.

Common issues

"Response format cannot be combined with image generation." Straight from the code: if include_images is on and you're on an image model, passing a schema raises. Turn off image generation, or disconnect the schema.

The node errors on queue with a name complaint. Blank or duplicate field names among enabled siblings, an enum line list with duplicates or nothing in it after whitespace, or a non-whole-number bound on an Integer. The error message names the field path.

Array needs its item definition. An Array with no item type won't compile. Same for an empty Object - it emits properties: {}, which not every model likes.

Your old node is stuck. Nodes from the earlier fixed-slot prototype aren't migrated for you. Delete and re-add the node, restart, and hard-refresh the browser so the web widget reloads.

Changing the schema triggers a fresh generation. The schema is part of the cache fingerprint, so edits invalidate it - correct behavior, not a bug. The pack uses the newer comfy_api node interface too, so a badly outdated ComfyUI won't register the node at all.

CategoryAPI/Gemini

Inputs (1)

NameTypeDefaultDescription
schema_stateGEMINI_SCHEMA_BUILDER{"version": 1, "root": "n0", "next_id": 1, "entries": {"n0": {"type": "object", "name": "", "required": true, "description": "", "fields": [], "item": null, "allowed_values": "any", "choices": "", "minimum_mode": "unbounded", "minimum": 0, "maximum_mode": "unbounded", "maximum": 0}}}

Outputs (2)

NameTypeDescription
schemaGEMINI_RESPONSE_SCHEMA
schema_jsonSTRING