Skip to content

fix: Avoid pydantic.ValidationError when the model stream returns empty final chunk #1706

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 30, 2025

Conversation

copybara-service[bot]
Copy link

fix: Avoid pydantic.ValidationError when the model stream returns empty final chunk

Bug: When a model emits a stream of tokens, it sometimes emits a final chunk of whitespace or no content. The agent was trying to parse that content into JSON, causing a validation error.

Fix: If a model is expected to return JSON and the last streamed token is empty/whitespace, the agent will no longer try to parse it, and exit gracefully.

New unit tests confirm the scenario and the fix.

@copybara-service copybara-service bot force-pushed the copybara/776719512 branch 2 times, most recently from 6c29fc8 to 5bf2865 Compare June 30, 2025 16:47
…ty final chunk

Bug: When a model emits a stream of tokens, it sometimes emits a final chunk of whitespace or no content. The agent was trying to parse that content into JSON, causing a validation error.

Fix: If a model is expected to return JSON and the last streamed token is empty/whitespace, the agent will no longer try to parse it, and exit gracefully.

New unit tests confirm the scenario and the fix.

PiperOrigin-RevId: 777609415
@copybara-service copybara-service bot force-pushed the copybara/776719512 branch from 5bf2865 to 9b75e24 Compare June 30, 2025 16:50
@copybara-service copybara-service bot merged commit 9b75e24 into main Jun 30, 2025
@copybara-service copybara-service bot deleted the copybara/776719512 branch June 30, 2025 16:50
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.

1 participant