Gemini Grounding with Google Search: Preserve Queries and Inline Citation Spans
Gemini grounded responses can expose search calls and URL citation spans. Preserve both before rendering, scoring, or rewriting the answer.
Direct answer: Gemini API responses grounded with Google Search can expose the search queries used by the system and URL citation annotations tied to character spans in the generated text. Preserve those fields with the original response before transforming or rendering it.
A citation UI is only the final layer. Reproducibility depends on the request, model, grounding configuration, search calls, raw text, URL annotations, timestamps, and any application-side changes. Losing one layer can turn a traceable answer into a decorative source list.
Separate the grounding record
| Layer | Record | Reason |
|---|---|---|
| Request | Prompt, model, tools, parameters | Defines the task and instrument |
| Search call | Query and call event | Shows retrieval activity |
| Answer | Unmodified returned text | Preserves citation offsets |
| Annotation | URL, title, start and end index | Maps evidence to a span |
| Render | Displayed text and links | Tests the user-facing result |
Do not collapse multiple queries into a single “searched the web” flag. The query sequence can explain why a source appeared, why a subtopic was missed, or why two runs produced different evidence.
Preserve spans before normalizing text
The citation annotation includes character offsets. Trimming whitespace, replacing Unicode characters, inserting Markdown, normalizing line endings, or merging response parts can shift those offsets. Apply citations to the exact returned string or create a tested offset map from the raw string to the rendered string.
- Save the raw response unchanged.
- Validate that each start and end index falls inside the returned text.
- Extract the span and store it beside the URL and title.
- Detect overlapping, adjacent, empty, or out-of-order annotations.
- Render from the structured record and compare the visible link with the expected span.
Test emoji, accented characters, right-to-left text, line breaks, and code samples. Index semantics can be mishandled when one layer counts bytes and another counts characters.
Audit the source-claim relationship
An annotation shows the source the system associated with a text range. It does not by itself prove that the source supports every claim inside that range. Open the URL, locate the relevant passage, identify the source owner, and classify the support as direct, qualified, conflicting, or absent.
Record redirects, inaccessible pages, changed content, duplicate sources, and citations that point to a search result or intermediary rather than the fact owner. Keep the retrieved title separate from the current page title because either can change.
Use the citation-ready passage test and the evidence-led publishing guide for claim-level skeptical review.
Make runs reproducible without ranking claims
Save the date, account or project, model version, API version, locale, prompt, tool configuration, safety settings, response, search calls, citations, errors, latency, and cost fields available to the application. Repeating the same request later is a new observation because the web, index, model, and product can change.
Do not describe a cited URL as “ranking in Gemini” or “ranking in Google AI” from one response. The citation is evidence that the URL was returned in a particular grounded answer under a particular environment. Stable prevalence requires a repeated, declared sample.
Pricing and supported models change. Read the current Gemini pricing and changelog before calculating cost or pinning a production model.
Ask a question or join the discussion