Nodes/ComfyUI Gemini Nodes/Gemini Structured Output
ComfyUI Node

Gemini Structured Output

Make Gemini return JSON you can actually build on

By jqy-yoΒ·Created about a year agoΒ·Updated 11 months agoΒ· 7
Gemini Structured Output
  • image
  • structured_output
  • raw_json
  • debug_request_sent
  • debug_response_received
β—„promptβ€”β–Ί
β—„api_keyβ–Ί
β—„modelgemini-2.0-flashβ–Ί
β—„output_modejson_schemaβ–Ί
β—„schema_json{ "type": "object", "properties": { "name": {"type": "string"}, "age": {"type": "integer"}, "email": {"type": "string"} }, "required": ["name", "age"] }β–Ί
β—„temperature0.70β–Ί
β—„max_output_tokens1024β–Ί
β—„seed0β–Ί
β—„system_instructionsβ–Ί
β—„enum_options["option1", "option2", "option3"]β–Ί
β—„top_p0.95β–Ί
β—„top_k64β–Ί
β—„property_orderingβ–Ί
β—„stop_sequencesβ–Ί
β—„presence_penalty0.0β–Ί
β—„frequency_penalty0.0β–Ί
β—„response_logprobsfalseβ–Ί
β—„logprobs0β–Ί
β—„use_json_schemafalseβ–Ί

Stop parsing prose, start parsing JSON

GeminiTextAPI is great until you need the model to hand you data instead of sentences. Ask it for a "name, price and stock status" and you'll get three different formats across three runs. GeminiStructuredOutput exists to fix exactly that: you give it a JSON schema, and it's contractually (well, API-ly) forced to reply with JSON that matches it. For anything that feeds a downstream node - a prompt builder, a LoRA picker, a save path - structured output is the difference between "it works" and "it works every run."

It's the second-most-used node in jqy-yo's pack for a reason: this is the piece that makes Gemini usable as a component of a pipeline rather than a chat window.

How it works

You pick an output_mode:

  • json_schema (default) - the model returns JSON validated against the schema_json you write. This is the full JSON Schema spec, so nested objects, arrays, enums and required fields all work.
  • enum - simpler. You provide a JSON array in enum_options like ["positive", "negative", "neutral"] and the model must pick one; the response comes back wrapped in a selection field.

There's also a use_json_schema toggle and an image input, so you can do vision-plus-schema - e.g. "analyze this image and return the schema's fields." That combo is where the node gets genuinely impressive.

Inputs worth knowing

The schema is the whole game, so spend your effort there:

  • schema_json - paste a JSON Schema object. The default is a sensible name/age/email template you can edit in place. Keep it focused; the pack's README is blunt that overly complex schemas produce errors.
  • property_ordering - comma-separated list of property names if you want keys to come back in a fixed order. Nice for consistency, easy to ignore.
  • temperature - drop to 0.1–0.3 for structured output. The model has less room to drift when you're constraining it anyway, but low temperature keeps fields stable.
  • stop_sequences, presence_penalty, frequency_penalty, logprobs - deeper generation controls. Beginners can leave them alone; they're there for when you're tuning something specific.

Outputs are structured_output (the formatted JSON, ready to feed onward), raw_json (the raw model response), and debug_request_sent / debug_response_received - the same full request/response dump every node in this pack gives you. When the schema rejects something, the debug outputs show you why.

Install

Same pack, same steps as the rest of the Gemini nodes:

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

Or search "ComfyUI Gemini Nodes" in ComfyUI Manager and restart. Needs a GOOGLE_API_KEY env var or the key pasted into the api_key field.

Where people get burned

Most failures here are schema problems, not API problems: invalid JSON in schema_json, or a required list naming a property that isn't defined. Test the schema with sample data before wiring it into a big workflow - the README says exactly this, and it saves you a session of staring at debug output. Also note the model matters: the pack's own MODEL_LIMITATIONS.md warns that gemini-2.5-flash-lite has spotty structured-output support, so use gemini-2.0-flash or better for schema work. When you get it dialed in, this node is the cleanest way to turn an LLM into a typed function inside your graph.

CategoryπŸ€– Gemini

Inputs (20)

NameTypeDefaultDescription
promptSTRINGβ€”
api_keySTRINGβ€”
modelSTRINGgemini-2.0-flashβ€”
output_modeCOMBOjson_schema2 options: json_schema, enum
schema_jsonSTRING{ "type": "object", "properties": { "name": {"type": "string"}, "age": {"type": "integer"}, "email": {"type": "string"} }, "required": ["name", "age"] }β€”
temperatureFLOAT0.700–1β€”
max_output_tokensINT102464–8192β€”
seedINT00–2147483647β€”
system_instructionsoptSTRINGβ€”
imageoptIMAGEβ€”
enum_optionsoptSTRING["option1", "option2", "option3"]β€”
top_poptFLOAT0.950–1β€”
top_koptINT641–100β€”
property_orderingoptSTRINGβ€”
stop_sequencesoptSTRINGβ€”
presence_penaltyoptFLOAT0.0-2–2β€”
frequency_penaltyoptFLOAT0.0-2–2β€”
response_logprobsoptBOOLEANfalseβ€”
logprobsoptINT00–10β€”
use_json_schemaoptBOOLEANfalseβ€”

Outputs (4)

NameTypeDescription
structured_outputSTRINGβ€”
raw_jsonSTRINGβ€”
debug_request_sentSTRINGβ€”
debug_response_receivedSTRINGβ€”