Search Grounding: Real-Time Data in Responses
Connect Google Search Tool to Gemini 2.0+ to generate current business reports with live data. Understand the difference between search grounding and the new search tool.
Build an agent that takes a list of companies from a CSV and generates a short report (3 sections: overview, recent news, financial highlights) for each, saving results to separate files.
Copy and adapt to your context. Text in angle brackets should be replaced.
from google import genai
from google.genai.types import GenerateContentConfig, Tool
client = genai.Client(api_key=GOOGLE_API_KEY)
MODEL_ID = "gemini-2.5-flash"
config = GenerateContentConfig(
system_instruction="You are a company analyst. Write concise reports.",
tools=[Tool(google_search={})],
temperature=0
)
response = client.models.generate_content(
model=MODEL_ID,
config=config,
contents=["Write a brief report on Apple Inc."]
)
print(response.text)Using the search tool with a free-tier account (will return an error); mixing search tool and search grounding in one request; not handling empty grounding_chunks.