Workflow

Gemini Search Fallback Workflow

Detect Gemini grounding search empty responses and automatically fall back to Scavio Google search. Keep your agent reliable during Gemini outages.

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

1

Send query to Gemini with grounding enabled

Call Gemini API with grounding search enabled. Capture the response including grounding citations and search results.

2

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.

3

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.

4

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.

5

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

Python
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

JavaScript
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

Google

Web search with knowledge graph, PAA, and AI overviews

Frequently Asked Questions

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.

This workflow uses a every agent query that uses gemini grounding search. Per agent query (event-driven).

This workflow uses the following Scavio platforms: google. Each platform is called via the same unified API endpoint.

Yes. Scavio's free tier includes 500 credits per month with no credit card required. That is enough to test and validate this workflow before scaling it.

Gemini Search Fallback Workflow

Detect Gemini grounding search empty responses and automatically fall back to Scavio Google search. Keep your agent reliable during Gemini outages.