[ ABORT TO HUD ]
SEQ. 1
SEQ. 2

Controlled JSON Generation

⚙️ Structured Outputs & Tools 12m 250 BASE XP⌨ HANDS-ON LAB

Ending Parsing Errors

When building applications, you often need the LLM to output structured data (like JSON) rather than plain text. Gemini supports response_schema.

from google.genai import GenerativeModel, ResponseSchema, Type

schema = ResponseSchema(
    type=Type.OBJECT,
    properties={
        "recipe_name": ResponseSchema(type=Type.STRING),
        "ingredients": ResponseSchema(
            type=Type.ARRAY,
            items=ResponseSchema(type=Type.STRING)
        ),
    },
    required=["recipe_name", "ingredients"]
)

response = model.generate_content(
    "Give me a recipe for pancakes.",
    generation_config={"response_mime_type": "application/json", "response_schema": schema}
)
⌨ HANDS-ON LABEnforce a Response Schema
⭐ +150 XP

Your pipeline chokes on Gemini's prose. Force pure JSON from the REST API with responseMimeType + responseSchema — no parsing regexes ever again.

1Capture an access token in the TOKEN variable.
2POST to generateContent with generationConfig containing responseMimeType application/json and a responseSchema.
lab-sandbox — simulated environment
INFINITY LAB SANDBOX v2.6 — simulated shell
Type the command for the current objective. Helpers: "hint", "solution", "clear".
$
OBJECTIVE 1 / 2 — type "hint" if stuck
SYNAPSE VERIFICATION
QUERY 1 // 1
What parameter must be set alongside `response_schema` to guarantee JSON output?
temperature=0
response_mime_type='application/json'
system_instruction='JSON ONLY'
format='json'