You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 16, 2025. It is now read-only.
When using response_schema in generate_content the response schema is not respected if the response_schema is set using a <class 'typing_extensions._TypedDictMeta'> object
The issue is probably that the fields are not set as "required".
Can that be done somehow?
Any other information you'd like to share?
Code where I explicit set the schema but also explicit asks it to not respect the schema (but it still should, according to documentation):
import typing_extensions as typing
import google.generativeai as genai
import os
class Recipe(typing.TypedDict):
recipe_name: str
ingredients: list[str]
genai.configure(api_key=os.environ["API_KEY"])
model = genai.GenerativeModel("gemini-1.5-pro-latest")
result = model.generate_content(
"List one popular cookie recipe. Response should be a JSON string on format {receipt_name: str}. There should only be one key in the response.",
generation_config=genai.GenerationConfig(
response_mime_type="application/json", response_schema=Recipe
),
)
print(result.text)