Google Search result source URL not available in code output

In AI Studio, it’s easy to see the google search’s sources used for the output

If i’m using the same code in python, the output only shows the website that’s using, instead of the actual sources,

After i added please include source url in output in prompt, then it hallucinated some urls within the source, since those are generated instead of the actual ones used.


Note: last link from Nikkei Asia doesn’t exist on website

Is there a way to natively output the links from grounded search in the python output? This would greatly improved output’s trustworthiness

Hey @cubesat , You should be able to get the actual source information (similar to what you see in AI Studio) by accessing the grounding metadata from the response.

response.to_json_dict()["candidates"][0]["grounding_metadata"]["grounding_chunks"]
1 Like

you were actually correct, the issue comes from AI Studio’s bug. I’ve made a bug report post, hope it can be fixed