AI / Google Antigravity Gemini Fundamentals Interview Questions
What is structured output (JSON mode) in the Gemini API and how do you implement it?
Structured output constrains Gemini to respond in valid JSON matching a developer-defined schema. This makes AI output reliably machine-readable without string parsing heuristics.
from google import genai from google.genai import types from pydantic import BaseModel from typing import Literal client = genai.Client() # Define schema with Pydantic class CodeReview(BaseModel): summary: str bugs: list[str] severity: Literal["low", "medium", "high", "critical"] line_numbers: list[int] suggested_fix: str # generateContent with response_schema: response = client.models.generate_content( model="gemini-3.5-flash", contents="Review this Python code: def add(a, b): return a - b", config=types.GenerateContentConfig( response_mime_type="application/json", response_schema=CodeReview, ) ) import json review = CodeReview(**json.loads(response.text)) print(f"Severity: {review.severity}") print(f"Bugs: {review.bugs}") # Interactions API structured output: interaction = client.interactions.create( model="gemini-3.5-flash", input="Extract: Alice is 30, an engineer from London.", response_mime_type="application/json", response_schema={"type": "object", "properties": { "name": {"type": "string"}, "age": {"type": "integer"}, "role": {"type": "string"}, "city": {"type": "string"} }} ) data = json.loads(interaction.output_text)
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
