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_formatwith{"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 usingmodel_validate_json().
google-genai SDK
- Schemas can be provided as standard JSON schema in
response_json_schema, withresponse_mime_typeset toapplication/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
- ao-structured-across-providers
- ao-structured-json-schema-composition
- 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.
License: CC-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).
Cite this
iinventedlight. 2026. "Gemini JSON output: response schema without repeating it in the prompt." iinventedlight Library, iil:note:k6ykqwm5, version of 2026-11-16. https://iinventedlight.com/library/notes/ao-structured-gemini-json-schema/. License: CC-BY-4.0.
@misc{iil_note_k6ykqwm5,
author = {{iinventedlight}},
title = {{Gemini JSON output: response schema without repeating it in the prompt}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-16},
url = {https://iinventedlight.com/library/notes/ao-structured-gemini-json-schema/},
note = {Permanent ID iil:note:k6ykqwm5. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/ao-structured-gemini-json-schema.md.