Skip to content

Menu

Build

Grounding and built-in tools

Use Google Search grounding and URL context to get checkable citations, and verify one by one that each citation supports the conclusion.

min read
15
Level
Intermediate
Last verified

After this page, you can add Google Search grounding or URL context to an API request and check whether the returned citations really support the adjacent conclusions. It is for developers who have finished the first API call.

A model’s training data has a cutoff, and it can invent plausible-looking details. Grounding makes the model retrieve first and then answer, and it returns its sources. It lowers the chance of fabrication but does not guarantee every conclusion is right, so citations must be checked one by one.

Scenario Needed?
The answer depends on recent events, new releases, or facts that are changing Yes
You need to show users clickable sources Yes
You only process material you supply yourself No; use long context or file input instead
You need to reach login-protected intranet or private pages Not applicable; the tool reads only public web pages

This page expands only Search grounding and URL context. For the other built-in tools, see the official pages:

These tools differ in model support and billing. Before writing code, read the “supported models” and “pricing” sections on the matching page.

Per the official docs, declare the tool as {"type": "google_search"} in an Interactions API request:

import os
from google import genai
client = genai.Client() # reads the GEMINI_API_KEY environment variable
interaction = client.interactions.create(
model=os.environ["GEMINI_MODEL"],
input="Briefly describe what changed in the latest major release of an open-source database project, and give sources.",
tools=[{"type": "google_search"}],
)
print(interaction.output_text)

Expected: an answer with facts, and citations attached in the response structure. The model decides whether to actually search, and it may search more than once. This example was not run with a real key; test it with your own fictional or public question.

The response is more than text. Per the official description, the key fields are:

  • google_search_call: the search queries the model actually ran (queries);
  • google_search_result: contains search_suggestions, an HTML snippet for showing search suggestions in your interface; see the terms page for usage requirements;
  • Text blocks with annotations: each url_citation gives the source url and title, plus the start_index and end_index of the text it supports.

Extract the citations in code and recover the cited passage:

for step in interaction.steps:
if step.type == "model_output":
for block in step.content:
if block.type == "text":
print(block.text)
for ann in (block.annotations or []):
if ann.type == "url_citation":
cited = block.text[ann.start_index:ann.end_index]
print(f"- [{ann.title}]({ann.url}) supports: {cited!r}")

This is the basis of inline citations: you can place each source after the sentence it supports in your interface. Field details and version differences follow the official pages and your SDK.

Having a citation does not mean it supports the conclusion. For each one, do three steps:

  1. Open the link and confirm the page exists and is reachable;
  2. Find the cited sentence and confirm the original says this, with the right numbers and dates;
  3. Check whether the source is authoritative and not a repost or aggregator.

In these cases, downgrade the conclusion to “unverified” and keep the evidence: the cited page is unrelated to the conclusion; the original does not contain this number; the source is a low-quality repost; the response has no citation yet states a firm claim.

For more checking methods, see Check the answer. For research in the App, see Research.

URL context: have the model read pages you specify

Section titled “URL context: have the model read pages you specify”

Declare {"type": "url_context"} and give full URLs (including https://) in the prompt. The limits Google lists:

  • At most 20 URLs per request;
  • A 34 MB content limit per URL;
  • URLs must be publicly accessible; localhost, private networks, and tunneling services are not supported;
  • Only the listed content types are supported; others fail.

So do not use it to read intranet docs or pages that need a login. To have the model read your own private files, use file input instead.

Per the official description, with Gemini 3 and newer models, grounding is billed per search query the model actually runs: two searches in one request count as two billable uses. Google also describes the free allowance, how billing works beyond it, and the default daily request limit on the paid tier. For the numbers, see the pricing page and the AI Studio rate-limit page; this page does not copy them.

URL context content is billed as input tokens. Before launch, measure once with a small amount of traffic to see the real number of searches and tokens.

Built-in tools and function calling can be combined in one interaction, letting the model verify online before calling your function. Google labels this a preview and requires a recent SDK version. Do not depend on a preview in production; see the tool-combination page for details.

Counterexample:

Write “be sure to be accurate” in the prompt, turn on search, and show the answer to users without looking at the citations.

Rewrite:

  • Show the sources together with the answer, and spot-check them as described in “Check every citation”;
  • Keep human review for high-risk conclusions (medical, legal, financial, compliance), and do not treat grounding as verification;
  • Hand data that needs precise citation to structured output so each field carries a source field.
  • The request declares the correct tool type and takes the model from an environment variable;
  • You can parse and display url_citation, and show the required search-suggestion content;
  • You spot-check at least three citations and confirm they support the adjacent conclusions;
  • You have assessed per-search billing and the daily limit;
  • You did not pass intranet or login-protected addresses to URL context;
  • Examples and logs contain no real keys or personal data.
Symptom Order of handling
The response has no citations The model may not have searched; ask in the prompt to “verify online and give sources,” and if there are still none, treat it as unverified
A citation link does not open Keep the link and the time, and check against other sources; do not treat a dead link as evidence
URL context fails Check that the address is public, the count and size are within limits, and the content type is supported
The tool and model do not match Return to the official “supported models” section and switch to a supported model
A limit error is returned Tell request rate apart from the tool’s daily limit; see Models and quotas
Search charges on the bill are high Check the actual number of searches and the pricing page, and narrow the questions that need search