Description
There is a syntax conflict in the official structured output documentation. The Python code blocks on the Structured outputs documentation page use a deeply nested raw dictionary structure for configuring JSON schemas.
config={
"response_format": {"text": {"mime_type": "application/json", "schema": Recipe.model_json_schema()}},
}
However, the modern google-genai Python SDK recommends and implements structured generation using flat, top-level keys within types.GenerateContentConfig (or equivalent dictionary mapping):
Example:
config={
response_mime_type="application/json",
response_schema=Recipe
}
Environment details
- Programming language: Python
- OS: linux-mint
- Language runtime version: 3.12.3
- Package version: 2.6.0
Steps to reproduce
-
Navigate to the documentation at: https://ai.google.dev/gemini-api/docs/structured-output
-
Observe the Python tabs under the "Recipe Extractor", "Streaming", and "Structured outputs with tools" sections.
-
They all use the nested "response_format" dictionary configuration instead of the native SDK schema parameters.
Making sure to follow these steps will guarantee the quickest resolution possible.
Thanks!
Description
There is a syntax conflict in the official structured output documentation. The Python code blocks on the Structured outputs documentation page use a deeply nested raw dictionary structure for configuring JSON schemas.
However, the modern
google-genaiPython SDK recommends and implements structured generation using flat, top-level keys withintypes.GenerateContentConfig(or equivalent dictionary mapping):Example:
Environment details
Steps to reproduce
Navigate to the documentation at: https://ai.google.dev/gemini-api/docs/structured-output
Observe the Python tabs under the "Recipe Extractor", "Streaming", and "Structured outputs with tools" sections.
They all use the nested
"response_format"dictionary configuration instead of the native SDK schema parameters.Making sure to follow these steps will guarantee the quickest resolution possible.
Thanks!