Gemini 2.5 pro has gotten worse in the last few days. When I search for a simple term I get really good results in google search but grounding is terrible.
Hi @Santhoshkumar199
Thanks for flagging this . Did you observe this when using in AI Studio or API ? Can you please share the prompt or minimally reproducible code so that i can try to reproduce from my end once.
I would say the issue is with both. This is my code
import os
from google import genai
from google.genai import types
def extract_grounded_urls(resp):
“”“Collect grounded web URIs from grounding_metadata.grounding_chunks.”“”
urls = \[\]
try:
if getattr(resp, “candidates”, None):
for cand in resp.candidates:
gmeta = getattr(cand, "grounding_metadata", None)
chunks = getattr(gmeta, "grounding_chunks", None) if gmeta else None
if chunks:
for ch in chunks:
web = getattr(ch, "web", None)
uri = getattr(web, "uri", None) if web else None
if uri and uri not in urls:
urls.append(uri)
except Exception as e:
print(f"[extract_grounded_urls] Error: {e}")
return urls
def generate():
# Accept either env var
api_key = os.environ.get("GEMINI_API_KEY") or os.environ.get("GOOGLE_API_KEY")
if not api_key:
raise RuntimeError(“Please set GEMINI_API_KEY or GOOGLE_API_KEY in the environment.”)
client = genai.Client(api_key=api_key)
# You can keep ‘gemini-flash-latest’ or switch to a specific model
model = "gemini-2.5-pro" # or "gemini-flash-latest"
#
Put your actual prompt here
user_prompt = (
“”"You are an expert e-commerce research specialist. Your mission is to analyze the web pages provided below and create a detailed profile for each one. **Product to Profile:** - Brand: Urban Revivo - Product Name: uwh250164 **Primary Search Target:** Your main goal is to find the specific product page for “uwh250164” on this official brand website: - urbanrevivo com **Required Output Format:** Create a “Product Profile” for each relevant page you analyze. Each profile must follow this exact markdown structure: — ### Product Profile - **Source URL:** [The full URL of the page] - **Page Type:** [Official Page | Retailer | Review | News | Other] - **Key Features:** - [List the specific features of the product mentioned on this page.] - **Key Benefits:** - [List the key benefits or selling points highlighted on this page
“”"
)
contents = \[
types.Content(
role="user",
parts=\[types.Part.from_text(text=user_prompt)\],
),
\]
# Enable Google Search tool for grounding
tools = \[types.Tool(googleSearch=types.GoogleSearch())\]
generate_content_config = types.GenerateContentConfig(
tools=tools,
# Optional thinking config; safe to keep or remove
thinking_config=types.ThinkingConfig(thinking_budget=-1),
)
# Use non-streaming so we can reliably extract grounding metadata in one go
resp = client.models.generate_content(
model=model,
contents=contents,
config=generate_content_config,
)
# Print the model text (if any)
try:
print(“=== Model Output ===”)
print(resp.candidates[0].content.parts[0].text)
except Exception:
pass
# Print grounded URLs
urls = extract_grounded_urls(resp)
print(“\n=== Grounded URLs ===”)
if urls:
for i, u in enumerate(urls, 1):
print(f"{i}. {u}")
else:
print(“(No grounded URLs found)”)
if _name_ == “_main_”:
generate()
Hi @Santhoshkumar199,
Your code is working exactly as expected. However, I’m curious about your comment regarding the ‘grounding’ being ‘terrible.’ Could you elaborate on what you meant by that—were you referring to the performance, or is there another issue we should be aware of?