Gemini Structured Output
Make Gemini return JSON you can actually build on
- image
- structured_output
- raw_json
- debug_request_sent
- debug_response_received
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_jsonyou 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_optionslike["positive", "negative", "neutral"]and the model must pick one; the response comes back wrapped in aselectionfield.
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.
Inputs (20)
| Name | Type | Default | Description |
|---|---|---|---|
| prompt | STRING | β | |
| api_key | STRING | β | |
| model | STRING | gemini-2.0-flash | β |
| output_mode | COMBO | json_schema | 2 options: json_schema, enum |
| schema_json | STRING | { "type": "object", "properties": { "name": {"type": "string"}, "age": {"type": "integer"}, "email": {"type": "string"} }, "required": ["name", "age"] } | β |
| temperature | FLOAT | 0.700β1 | β |
| max_output_tokens | INT | 102464β8192 | β |
| seed | INT | 00β2147483647 | β |
| system_instructionsopt | STRING | β | |
| imageopt | IMAGE | β | |
| enum_optionsopt | STRING | ["option1", "option2", "option3"] | β |
| top_popt | FLOAT | 0.950β1 | β |
| top_kopt | INT | 641β100 | β |
| property_orderingopt | STRING | β | |
| stop_sequencesopt | STRING | β | |
| presence_penaltyopt | FLOAT | 0.0-2β2 | β |
| frequency_penaltyopt | FLOAT | 0.0-2β2 | β |
| response_logprobsopt | BOOLEAN | false | β |
| logprobsopt | INT | 00β10 | β |
| use_json_schemaopt | BOOLEAN | false | β |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| structured_output | STRING | β |
| raw_json | STRING | β |
| debug_request_sent | STRING | β |
| debug_response_received | STRING | β |