Skip to content

fix: accept grounding chunk metadata#2562

Open
he-yufeng wants to merge 1 commit into
googleapis:mainfrom
he-yufeng:fix/grounding-chunk-metadata
Open

fix: accept grounding chunk metadata#2562
he-yufeng wants to merge 1 commit into
googleapis:mainfrom
he-yufeng:fix/grounding-chunk-metadata

Conversation

@he-yufeng

Copy link
Copy Markdown
Contributor

Summary

Fixes #2510.

Some Vertex batch responses with Google Search grounding include groundingMetadata.groundingChunks[].chunkMetadata. The SDK currently rejects that payload because GroundingChunk forbids unknown fields and does not declare chunk_metadata.

This adds the field to both the model and TypedDict shape so the response can validate without dropping the metadata.

Testing

python -m pytest google\genai\tests\types\test_types.py::test_generate_content_response_accepts_grounding_chunk_metadata -q
python -m pytest google\genai\tests\types\test_types.py -q
python -m py_compile google\genai\types.py google\genai\tests\types\test_types.py
git diff --check

I also ran python -m pyink --check google\genai\types.py google\genai\tests\types\test_types.py; it wants to reformat the existing generated/style-preserved files wholesale, so I did not apply it.

@Venkaiahbabuneelam Venkaiahbabuneelam self-assigned this Jun 8, 2026
@Venkaiahbabuneelam Venkaiahbabuneelam added the size:M Code changes between 10-40 lines label Jun 8, 2026
@he-yufeng he-yufeng force-pushed the fix/grounding-chunk-metadata branch from b0f54e0 to 1bb2fbb Compare June 12, 2026 11:44
@he-yufeng

Copy link
Copy Markdown
Contributor Author

Rebased this branch onto current main and pushed the updated head 1bb2fbb.

Validation:

  • python -m pytest google\genai\tests\types\test_types.py -q -k "grounding or metadata or chunk" -> passed, 1 passed
  • python -m py_compile google\genai\types.py google\genai\tests\types\test_types.py -> passed
  • git diff --check upstream/main..HEAD -> passed

@he-yufeng he-yufeng force-pushed the fix/grounding-chunk-metadata branch from 1bb2fbb to ca46014 Compare June 12, 2026 14:10
@he-yufeng he-yufeng force-pushed the fix/grounding-chunk-metadata branch from ca46014 to 1845f03 Compare June 12, 2026 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M Code changes between 10-40 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validating batch response with Google Search grounding against GenerateContentResponse causes validation error

2 participants