When building applications, you often need the LLM to output structured data (like JSON) rather than plain text. Gemini supports response_schema.
from vertexai.generative_models import GenerativeModel, ResponseSchema, Type
schema = ResponseSchema(
type=Type.OBJECT,
properties={
"recipe_name": ResponseSchema(type=Type.STRING),
"ingredients": ResponseSchema(
type=Type.ARRAY,
items=ResponseSchema(type=Type.STRING)
),
},
required=["recipe_name", "ingredients"]
)
response = model.generate_content(
"Give me a recipe for pancakes.",
generation_config={"response_mime_type": "application/json", "response_schema": schema}
)