Working with Data Structures and Schemas in Gemini Function Calling
Source notebook
Repo path:
gemini/function-calling/function_calling_data_structures.ipynb· Open on GitHub · intro
Shows how to extract structured function-call arguments from Gemini using simple, array, and nested schemas.
Summary
This notebook teaches Gemini Function Calling with Google GenAI SDK on Vertex AI. It creates FunctionDeclaration schemas for single parameters, multiple parameters, arrays of objects, and nested objects, then calls client.models.generate_content with tools and temperature 0 to inspect response.function_calls. The examples cover travel destinations, geocoding multiple locations, and product listing extraction.
Key code patterns
Vertex GenAI client
from google import genai
client = genai.Client(
vertexai=True,
project=PROJECT_ID,
location="global",
)Initializes the Google GenAI SDK for Vertex AI with project and location.
Function schema as tool
get_destination = FunctionDeclaration(
name="get_destination",
description="Get directions to a destination",
parameters={"type": "object", "properties": {...}},
)
destination_tool = Tool(function_declarations=[get_destination])Wraps a declared JSON-like parameter schema as a Gemini function-calling tool.
Generate function call
response = client.models.generate_content(
model=MODEL_ID,
contents=prompt,
config=GenerateContentConfig(
temperature=0,
tools=[destination_tool],
),
)
response.function_callsSends a prompt with tools enabled and reads the structured function-call output.
Array and nested parameters
parameters={
"type": "object",
"properties": {
"locations": {
"type": "array",
"items": {"type": "object", "properties": {...}},
}
},
}Shows how to request lists of structured objects and nested data from the model.
Models & APIs used
- Models: gemini-3.5-flash
- APIs / services: Vertex AI, Gemini API
- SDKs / libraries:
google-genai
When to use this
Use this pattern when prompts need to be converted into structured arguments for downstream functions or APIs.
Gotchas & caveats
- Requires an existing Google Cloud project with the Vertex AI API enabled.
- Colab users must authenticate with google.colab.auth.authenticate_user().
- PROJECT_ID must be set directly or through the GOOGLE_CLOUD_PROJECT environment variable.
- The notebook uses LOCATION = “global”.
- Required fields in the array item schema drive the model to populate all required location parameters.
Best practices
- Use explicit FunctionDeclaration names, descriptions, parameter types, and property descriptions.
- Set temperature=0 for deterministic structured extraction examples.
- Wrap function declarations in Tool objects before passing them to GenerateContentConfig.
- Use required fields when every object in an array must include specific parameters.
- Inspect response.function_calls to retrieve the structured function name and arguments.
Related
- Concepts: Function Calling & Tools
- Entities: Vertex AI · Google GenAI SDK · Function Calling · Gemini
- Area: Gemini Notebooks
- Best practices: Function Calling & Tools - Best Practices