fix(gemini): add additionalContent with grounding metadata to Structured handler #828
+7
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Add
additionalContentwith grounding metadata (citations, search queries, URL metadata) to the Gemini Structured handler, matching the behavior of the Text handler.Problem
When using Gemini with provider tools like
google_searchfor structured responses, the grounding metadata (citations, web search queries, search entry point, URL metadata) is returned by the API but not captured in the response.The
Texthandler correctly captures this data inadditionalContent(lines 201-207), but theStructuredhandler does not (line 227+).This means:
Prism::structured()withgoogle_searchtool → No citations availablePrism::text()withgoogle_searchtool → Citations available ✓Solution
Add the same
additionalContentpopulation toStructured.phpthat exists inText.php:Changes
src/Providers/Gemini/Handlers/Structured.php:use Prism\Prism\Providers\Gemini\Maps\CitationMapper;additionalContentparameter toStepconstructor inaddStep()methodTesting
Verified fix works by:
google_searchprovider tooladditionalContent['citations']is now populated with 6 citationsadditionalContentwas emptyRelated
This brings
Structured.phpin line withText.phpbehavior for Gemini grounding metadata.