response = model.generate_content(
"List a few popular cookie recipes",
generation_config=GenerationConfig(
response_mime_type="application/json", response_schema=response_schema
),
)
`
Until the JSON output support is done, I think using pydantic model with JsonOutputParser on the unstructured/text output has a good performance. Even though it requires an additional call, validity-wise it's good.
Checked other resources
Example Code
The underlying googlegemini supports JSON mode and response type with gemini. Is there a way to update the documentation with an example of this?
` response_schema = { "type": "ARRAY", "items": { "type": "OBJECT", "properties": { "recipe_name": { "type": "STRING", }, }, "required": ["recipe_name"], }, }
response = model.generate_content( "List a few popular cookie recipes", generation_config=GenerationConfig( response_mime_type="application/json", response_schema=response_schema ), ) `
Error Message and Stack Trace (if applicable)
No response
Description
im trying to use gemini pro 1.5 with forced JSON output as documented here: https://github.com/GoogleCloudPlatform/generative-ai/blob/main/gemini/controlled-generation/intro_controlled_generation.ipynb
System Info
langchain==0.2.12 langchain_core==0.2.29 langchain_google_genai==1.0.8 google-generativeai==0.7.2