Skip to content

[vertexai]: ignore empty AIMessage from previous blocked responses #929

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

aabmass
Copy link

@aabmass aabmass commented May 19, 2025

PR Description

Filter out any AIMessage from previous blocked interactions with a model. See issue description for details of when this comes up.

Other messages with empty content will still be passed through and error out.

Relevant issues

Fixes #886

Type

🐛 Bug Fix

Testing(optional)

Added a new integration test. I made sure the test was failing before the fix.

@@ -357,6 +357,12 @@ def _convert_to_parts(message: BaseMessage) -> List[Part]:
prev_ai_message = message
role = "model"

# Previous blocked messages will have empty content which should be ignored
if not message.content and message.response_metadata.get(
"is_blocked", False
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it be message.response_metadata.get("is_blocked", True) instead maybe?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that if someone does this by accident it's better to let the API yell at them than sanitize the data

model.invoke([AIMessage(content="")])

But whatever you think is best, maybe there are other cases where the content is empty

@aabmass aabmass requested a review from lkuligin May 19, 2025 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ChatVertexAI incompatible with pre-built ReAct agent when responses are blocked
2 participants