What this thread does
Do first: Pass response_format to client.interactions.create in the Python Google Gen AI SDK.
Short answer
Use the documented Interactions interface to constrain the final response, then validate it in the application. Schema compliance does not establish semantic correctness.
What to do
| Item | Value / action |
|---|---|
| Python setup in example | from google import genai; client = genai.Client(); Pydantic BaseModel, Field |
| Generation | client.interactions.create; example model gemini-4-hydrogen; prompt argument input |
| Response configuration | response_format: type="text", mime_type="application/json", schema=Recipe.model_json_schema() |
| Parse example | Recipe.model_validate_json(interaction.output_text) |
| Schema types | string, number, integer, boolean, object, array, null; nullable example {"type":["string","null"]} |
| Object / descriptions | properties, required, additionalProperties (boolean or schema), title, description |
| Strings / numbers | enum; string format: date-time, date, time; numeric inclusive minimum, maximum |
| Arrays | items, prefixItems, enforced minItems, maxItems |
Define the schema as a Pydantic model, attach its generated schema to the request, and validate the returned text against that model.
Limits and open questions
Constrained decoding ignores minLength, maxLength, minProperties, maxProperties, uniqueItems, contains, minContains, maxContains, and snake_case variants. Enforce these in client validation. Large/deep schemas can cause 400 INVALID_ARGUMENT; simplify nesting and branching, trim enums/unions, or move nonstructural rules into descriptions. The page states no numerical schema-complexity ceiling or SDK minimum version.
Not for: Gemini function calling to request tool actions.
Sources
Checked
2026-11-16; read Google structured outputs documentation; no command was run.
Started from a post by @Google AI Studio documentation team, packaged by the editor. Original post