Skip to content

Unable to load content using URL context for URLs retrieved with Grounding with Google Search #1322

Description

@mazayo

Environment details

  • Programming language: Python
  • OS: Windows 11 Pro 24H2
  • Language runtime version: Python 3.12.4
  • Package version: 1.31.0

Executed Code and Observed Issue

Grounding with Google Search with URL context states the following:
'You can also enable both URL context and Grounding with Google Search together. You can enter a prompt with or without URLs. The model may first search for relevant information and then use the URL context tool to read the content of the search results for a more in-depth understanding.'

However, when I executed the following code, the attempt to retrieve page details using the URL context functionality failed, and Gemini provided incorrect information. When I asked Gemini about the reason for the failure, it provided the following explanation:

  • The URLs retrieved from search results are in grounding-api-redirect format
  • My (Gemini's) browse tool cannot track redirected URLs to retrieve the content of the original page

Indeed, the uri in grounding_chunks shows redirect URLs like the following, and without following the redirect, it's impossible to know the destination URL:
'https://vertexaisearch.cloud.google.com/grounding-api-redirect/AUZIYQHmpj-dfVvwMUMsUWVVNY0Mub_BmeYdZegGil3-VZ4QF2d5KeS5CRYrrbOgOl30HD4CWYm4ipKeHJdC7BjNYNnirsZ3uevAjQtFl1dDxJCy_GsLqOOa7Qqe4IeJ2A=='

When I provided the destination URL in the prompt, Gemini was able to use the URL context tool to derive the correct answer. Therefore, as Gemini's response indicated, I believe the cause of this issue is that the URLs from Grounding with Google Search results are returned in redirect format.

from google import genai
from google.genai.types import Tool, GenerateContentConfig, HttpOptions, UrlContext, GoogleSearch

client = genai.Client(http_options=HttpOptions(api_version="v1beta1"))  # instantiated using the `Vertex AI API`
model_id = "gemini-2.5-flash"

tools = []
tools.append(Tool(url_context=UrlContext))
tools.append(Tool(google_search=GoogleSearch))

contents = (
    "Vertex AIでは、grounding with Google Searchの機能で取得したURLをもとに、URL contextの機能を使ってページの詳細を取得することは可能ですか?"
    # Translation: Is it possible in Vertex AI to retrieve page details using the URL context feature based on URLs obtained through the grounding with Google Search functionality?
    "試しに、大阪万博のナショナルデーが、9月28日にどの国に割り当てられているかを調べることで、可能であることを示してください。"
    # Translation: As a test, please demonstrate that this is possible by looking up which country is assigned to the National Day on September 28th for the Osaka Expo.
)

response = client.models.generate_content(
    model=model_id,
    contents=contents,
    config=GenerateContentConfig(
        tools=tools,
        response_modalities=["TEXT"],
    )
)

for each in response.candidates[0].content.parts:
    print(each.text)

Metadata

Metadata

Assignees

Labels

priority: p3Desirable enhancement or fix. May not be included in next release.status:awaiting user responsetype: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions