What this prompt does
This prompt implements Gemini grounding with Google Search so responses stay factual and current with real source citations. It covers six steps: configuring search grounding with a dynamic retrieval threshold, applying grounding-aware prompt engineering, parsing and displaying grounding metadata, building a grounding-quality evaluation pipeline, adding caching and cost optimization, and creating a grounded-vs-ungrounded comparison test. Tuning the threshold per use case and rendering real citations is what makes the output trustworthy rather than confidently wrong.
The variables tailor grounding to your app. [retrieval_threshold] controls how often the model grounds, [use_case_count] and [use_cases] set where grounding applies, and [topic_area] plus [time_window] shape the prompts. [analytics_store] and [quality_threshold] drive evaluation, [news_ttl], [reference_ttl], and [cache_target] configure caching, and [test_query_count] sizes the comparison framework. The retrieval threshold is the lever that decides whether a query type always searches or relies on the model's training knowledge.
When to use it
- You are building a research or assistant feature where stale or hallucinated facts are unacceptable.
- You need responses grounded in current web results with inline source citations.
- You want to tune the retrieval threshold per use case so creative tasks don't over-ground.
- You need to parse grounding metadata and render clickable source links.
- You want a quality pipeline that flags low-grounding responses for review.
- You want to compare grounded vs ungrounded responses to decide where grounding earns its cost.
Example output
Expect a Gemini configuration with google_search_retrieval and a [retrieval_threshold], plus grounding-aware prompt templates referencing [topic_area] and [time_window] and instructing the model to cite sources. The parsing step turns groundingMetadata (chunks, supports, search queries) into a citation UI with inline links. Later steps add a quality evaluation that stores metrics in [analytics_store] and flags responses below [quality_threshold], a caching layer with [news_ttl] and [reference_ttl], and a comparison test over [test_query_count] queries that scores accuracy, recency, and cost. It blends config, parsing code, and evaluation, with the citation rendering treated as a first-class feature so users can verify every grounded claim.
Pro tips
- Set
[retrieval_threshold]per use case: low for factual queries that should always search, higher for creative or opinion tasks. - Write prompts that name the
[topic_area]and[time_window]and explicitly ask the model to cite sources, which triggers attribution. - Render the
groundingSupportsmapping as inline citations so users can trace each claim to its source chunk. - Cache stable queries with
[reference_ttl]and volatile ones with[news_ttl]; caching news too long defeats the point of grounding. - Evaluate citation quality on real queries before trusting it; flag anything below
[quality_threshold]for human review. - Use the
[test_query_count]comparison to find query types that don't benefit from grounding and run those ungrounded to save cost and latency.