Listen: Prompt Engineer’s Guide to Gemini Schemas

A technical guide to the Gemini API GenerateContentResponse schema, detailing the structure of candidates, usage metadata, safety ratings, and parsed data.

Listen

Transcript

When you work with the Gemini API, the output response is a rich, nested structure designed to handle complex, multimodal data. At the core of this response is a list of candidates, which are the different variations of content the model generates.

Because Gemini is multimodal, this content is broken down into distinct parts. A single part can carry plain text, embedded images, function calls, or even executable code. If you request a structured output using a response schema, the API can automatically parse the generated candidate into your specified format, making it ready to use in your code.

Beyond the generated content itself, the response provides crucial metadata. Safety ratings evaluate both your input prompt and the model's output for potential harm. Meanwhile, usage metadata tracks precise token counts, including cached content and tool prompts, which is essential for managing your billing.

Finally, if your model interacts with external systems or retrieves web data through Retrieval-Augmented Generation, often called RAG, the response includes grounding metadata. This metadata allows you to trace exactly which external sources the model relied on to formulate its answer.

By understanding these core components, you can build more robust, safe, and cost-effective applications with Gemini.