Overview
This workflow wraps Gemini grounding search with a response validator. When Gemini returns an empty grounding context (a known intermittent issue since April 2026), the workflow routes the same query to Scavio Google search and merges results into the agent's context. The agent self-heals without user-visible degradation.
Trigger
Every agent query that uses Gemini grounding search
Schedule
Per agent query (event-driven)
Workflow Steps
Send query to Gemini with grounding enabled
Call Gemini API with grounding search enabled. Capture the response including grounding citations and search results.
Validate grounding response
Check if grounding_citations array is non-empty and search results contain actual content. An empty array or missing grounding context indicates a silent failure.
Fallback to Scavio on empty grounding
If validation fails, send the same query to Scavio Google search endpoint. Extract organic results with titles, snippets, and URLs.
Merge results into agent context
Format Scavio results as grounding citations and inject them into the agent's context block. The agent proceeds as if Gemini grounding succeeded.
Log fallback event
Record the fallback event with timestamp, query, and Gemini response status for monitoring. Track fallback frequency to assess Gemini reliability.
Python Implementation
import requests, os, json, datetime
SCAVIO_KEY = os.environ["SCAVIO_API_KEY"]
def gemini_search_with_fallback(query: str, gemini_response: dict) -> dict:
citations = gemini_response.get("grounding_citations", [])
if citations:
return {"source": "gemini", "citations": citations}
# Gemini returned empty grounding — fallback
resp = requests.post("https://api.scavio.dev/api/v1/search",
headers={"x-api-key": SCAVIO_KEY},
json={"platform": "google", "query": query}, timeout=10)
data = resp.json()
fallback_citations = [
{"title": r["title"], "snippet": r["snippet"], "url": r["link"]}
for r in data.get("organic", [])[:5]
]
# Log fallback event
with open("fallback_log.jsonl", "a") as f:
f.write(json.dumps({"ts": datetime.datetime.utcnow().isoformat(),
"query": query, "gemini_status": "empty_grounding"}) + "\n")
return {"source": "scavio_fallback", "citations": fallback_citations}JavaScript Implementation
async function geminiSearchWithFallback(query, geminiResponse) {
const citations = geminiResponse.grounding_citations || [];
if (citations.length > 0) return { source: "gemini", citations };
const resp = await fetch("https://api.scavio.dev/api/v1/search", {
method: "POST",
headers: { "x-api-key": process.env.SCAVIO_API_KEY, "Content-Type": "application/json" },
body: JSON.stringify({ platform: "google", query })
});
const data = await resp.json();
const fallbackCitations = (data.organic || []).slice(0, 5).map(r => ({
title: r.title, snippet: r.snippet, url: r.link
}));
console.log(JSON.stringify({ ts: new Date().toISOString(), query, gemini_status: "empty_grounding" }));
return { source: "scavio_fallback", citations: fallbackCitations };
}Platforms Used
Web search with knowledge graph, PAA, and AI overviews