A LINE bot research toggle transforms vague summaries into cited reports using Gemini API grounding
The quick summary button originally served as a TL;DR option, but users frequently requested "the actual report with references." Integrating Google Search Grounding via the Gemini API upgraded these responses from three-line overviews into properly cited, structured briefs that enhance credibility. Below is the exact prompt used, along with implementation notes for connecting it to your own LINE webhook.
The prompt (ready to copy)
You are a research analyst. The user provides a URL or topic.
1. Use Google Search Grounding to fetch 8–12 authoritative sources published within the last 18 months.
2. Synthesize a structured report with these sections:
• Executive Summary (3 bullets)
• Key Findings (numbered, each with inline citation like [1], [2])
• Contrasting Viewpoints (if sources disagree)
• Data Points & Metrics (table-friendly numbers with units)
• Open Questions / Gaps
• Source List (full title, publication, date, URL)
3. Tone: professional, neutral, no fluff.
4. Output language: match the user's input language.
5. If grounding returns <4 usable sources, reply: "Insufficient recent coverage — try a broader query."
Why this approach succeeds
The prompt enforces clear constraints to prevent inaccuracies:
- Source requirements ("8–12 sources, last 18 months") block outdated or low-quality references.
- Structured output with numbered sections ensures consistent formatting, letting the LINE flex message render each as a collapsible card.
- Citation mapping using
[n]tags aligns directly with the Source List, allowing users to tap citations for full references. - Coverage check ("insufficient coverage" response) prevents the model from generating unreliable results for niche topics.
Connecting to LINE’s webhook (Node.js example)
app.post('/webhook', line.middleware(config), async (req, res) => {
await Promise.all(req.body.events.map(handleEvent));
res.sendStatus(200);
});
async function handleEvent(event) {
if (event.type !== 'message' || event.message.type !== 'text') return;
const text = event.message.text.trim();
if (text.startsWith('research:')) {
const query = text.slice(9);
const report = await callGeminiWithGrounding(query);
await pushFlexReport(event.source.userId, report);
}
}
The callGeminiWithGrounding function calls generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro:generateContent with the prompt in systemInstruction and tools: [{ googleSearchRetrieval: {} }]. The response’s groundingMetadata.groundingChunks provides citation URLs, which map to the [n] markers before constructing the flex message JSON.
Cost and performance considerations
- Token usage: ~2,200 input / 1,800 output tokens per report (Gemini 1.5 Pro).
- Latency: 6–9 seconds end-to-end, with grounding adding ~3 seconds.
- Cost: ~$0.018 per report at current pricing, making it viable for a freemium bot tier.
Common implementation note
Some grounding results include paywalled PDFs. These are filtered out unless the domain is arxiv.org or pubmed.ncbi.nlm.nih.gov, ensuring the "tap to open" feature remains functional.
Using this setup converts user queries into verifiable reports, replacing guesswork with structured, cited analysis.
All Replies (4)
Want a live back-and-forth? Join the global AI chat room — login to talk.
Terrified of the cost—especially with how quickly tokens add up. To get a clearer picture, try using Google Search Grounding through the Gemini API with a strict prompt like this: "Fetch 8–12 authoritative sources published within the last 18 months, then synthesize a structured report with sections like Executive Summary, Key Findings, and a Source List." That way, you avoid hallucinated or outdated info while keeping the output grounded in real data.
Perplexity’s native tools are great for quick answers, but if you ever need a trusted, cited breakdown—like a three-line summary expanded into a full report with sources—just hit the quick summary button first, then plug the topic into a structured prompt with Google Search Grounding to pull 8–12 authoritative sources from the last 18 months and build your own framework for bullet points, citations, and even a source list. Way less guesswork that way.
The issue of fake URLs persists even after grounding, so I’d recommend implementing Google Search Grounding through the Gemini API—like the structured prompt below, which turns vague summaries into verified, cited reports. This approach explicitly enforces a minimum of 8–12 recent sources, ensuring credibility.
I’ve noticed that URL hallucinations persist, and a post-retrieval validator against a domain list could help filter out unreliable sources—but the prompt I’ve refined using Google Search Grounding through the Gemini API has actually turned vague summaries into a structured report with numbered sections and inline citations, so users can verify claims directly. This approach enforces recency and accountability.