---
source: https://iinventedlight.com/library/notes/ao-structured-gemini-json-schema.md
title: "Gemini JSON output: response schema without repeating it in the prompt"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "Apache-2.0 (google-gemini/cookbook (GitHub)); Apache-2.0 (googleapis/python-genai (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: google-gemini/cookbook (GitHub), JSON mode quickstart, Apache-2.0 (https://raw.githubusercontent.com/google-gemini/cookbook/main/LICENSE); googleapis/python-genai (GitHub), Google Gen AI Python SDK README, Apache-2.0 (https://raw.githubusercontent.com/googleapis/python-genai/main/LICENSE)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-16
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-16
as_of: 2026-11-16
confidence: medium
untested: "Not reproduced (2026-11-16). Docs read; no API call was made for this note."
category: agent-operations
topic_area: "agent operations: structured output"
tags: [gemini, structured-output, json-schema, pydantic, google-genai]
client: Librarian
sources:
  - id: S1
    title: "JSON mode quickstart"
    publisher: google-gemini/cookbook (GitHub)
    url: https://github.com/google-gemini/cookbook/blob/main/quickstarts/JSON_mode.ipynb
    accessed: 2026-11-16
    license: "Apache-2.0"
  - id: S2
    title: "Google Gen AI Python SDK README"
    publisher: googleapis/python-genai (GitHub)
    url: https://github.com/googleapis/python-genai/blob/main/README.md
    accessed: 2026-11-16
    license: "Apache-2.0"
---
# Gemini JSON output: response schema without repeating it in the prompt
**Answer:** With Gemini you can either set the desired output in the prompt or supply a schema separately. With a schema, the model output will then follow that schema exactly.

## Cookbook (Interactions API)

- `response_format` with `{"type": "text", "mime_type": "application/json"}` asks for only valid JSON. Without that parameter, the model might wrap the JSON in markdown code blocks.
- Define the schema as a Python class using Pydantic and use `.model_json_schema()` to generate the JSON Schema automatically. You can also validate the response directly into your Pydantic model using `model_validate_json()`.

## google-genai SDK

- Schemas can be provided as standard JSON schema in `response_json_schema`, with `response_mime_type` set to `application/json`. Schemas can also be provided as Pydantic models.
- The README says don't duplicate the schema in your input prompt, not even as examples of expected JSON output. Doing so might lower the quality of the generated output.

## See also

- [ao-tools-gemini-function-calling](https://iinventedlight.com/library/notes/ao-tools-gemini-function-calling/)
- [ao-structured-across-providers](https://iinventedlight.com/library/notes/ao-structured-across-providers/)
- [ao-structured-json-schema-composition](https://iinventedlight.com/library/notes/ao-structured-json-schema-composition/)
- [ao-structured-json-schema-objects](https://iinventedlight.com/library/notes/ao-structured-json-schema-objects/)

## Claims

- id: C1
  claim: Gemini supports prompt or separate schema.
  source: S1
  evidence: "set the desired output in the prompt or supply a schema to the model separately"

- id: C2
  claim: Output follows the supplied schema.
  source: S1
  evidence: "The model output will then follow that schema exactly."

- id: C3
  claim: Do not duplicate the schema in the prompt.
  source: S2
  evidence: "don't duplicate it in your input prompt"

## Sources

- [S1] JSON mode quickstart. google-gemini/cookbook (GitHub). https://github.com/google-gemini/cookbook/blob/main/quickstarts/JSON_mode.ipynb . License: Apache-2.0. Accessed 2026-11-16.

- [S2] Google Gen AI Python SDK README. googleapis/python-genai (GitHub). https://github.com/googleapis/python-genai/blob/main/README.md . License: Apache-2.0. Accessed 2026-11-16.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: google-gemini/cookbook (GitHub), JSON mode quickstart, Apache-2.0 (https://raw.githubusercontent.com/google-gemini/cookbook/main/LICENSE); googleapis/python-genai (GitHub), Google Gen AI Python SDK README, Apache-2.0 (https://raw.githubusercontent.com/googleapis/python-genai/main/LICENSE). Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
