Skip to content

fix: prevent dropping grounding-only responses in BaseLlmFlow#1351

Merged
copybara-service[bot] merged 1 commit into
google:mainfrom
hemasekhar-p:p1-grounding-metadata-dropping-issue-fix
Jul 14, 2026
Merged

fix: prevent dropping grounding-only responses in BaseLlmFlow#1351
copybara-service[bot] merged 1 commit into
google:mainfrom
hemasekhar-p:p1-grounding-metadata-dropping-issue-fix

Conversation

@hemasekhar-p

Copy link
Copy Markdown
Contributor

Please ensure you have read the contribution guide before creating a pull request.

Problem:
ADK Java BaseLlmFlow drops a model response that has grounding metadata but no content, because the "skip empty response" guard in buildPostprocessingEvents does not check groundingMetadata. adk-python keeps such responses. This is a Python-parity gap that can silently lose grounding metadata (e.g. Google Search / citation grounding) on responses that carry no other content.

Solution:
Added && updatedResponse.groundingMetadata().isEmpty() to the skip condition in buildPostprocessingEvents. This ensures that grounding-only response (no content) should produce one emitted event. Also added unit

Testing Plan

Please describe the tests that you ran to verify your changes. This is required
for all PRs that are not small documentation or typo fixes.

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Added the postprocess_onlyGroundingMetadata_returnsEvent regression test in BaseLlmFlowTest.java. This test simulates a live API chunk by injecting a LlmResponse payload containing only GroundingMetadata. It successfully verifies that the postprocess method emits the event (returning a list of size 1) instead of incorrectly dropping it.

Checklist

  • I have read the CONTRIBUTING.md document.
  • My pull request contains a single commit.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.

@hemasekhar-p hemasekhar-p self-assigned this Jul 14, 2026
@hemasekhar-p hemasekhar-p force-pushed the p1-grounding-metadata-dropping-issue-fix branch from ca99713 to 20bd26a Compare July 14, 2026 09:03
@hemasekhar-p hemasekhar-p force-pushed the p1-grounding-metadata-dropping-issue-fix branch from 20bd26a to 5146e5d Compare July 14, 2026 11:46
Comment thread core/src/test/java/com/google/adk/flows/llmflows/BaseLlmFlowTest.java Outdated
@damianmomotgoogle damianmomotgoogle added the waiting on reporter Waiting for reaction by reporter. Failing that, maintainers will eventually closed it as stale. label Jul 14, 2026
@hemasekhar-p hemasekhar-p force-pushed the p1-grounding-metadata-dropping-issue-fix branch from 5146e5d to 1a62158 Compare July 14, 2026 12:41
@damianmomotgoogle damianmomotgoogle added ready to pull and removed waiting on reporter Waiting for reaction by reporter. Failing that, maintainers will eventually closed it as stale. labels Jul 14, 2026
@hemasekhar-p hemasekhar-p force-pushed the p1-grounding-metadata-dropping-issue-fix branch from 1a62158 to 4de0d8c Compare July 14, 2026 12:47
@copybara-service copybara-service Bot merged commit cb22de6 into google:main Jul 14, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants