fix(rag): avoid empty system messages that crash Vertex AI#426
Merged
basnijholt merged 1 commit intomainfrom Feb 12, 2026
Merged
fix(rag): avoid empty system messages that crash Vertex AI#426basnijholt merged 1 commit intomainfrom
basnijholt merged 1 commit intomainfrom
Conversation
When no RAG context is found, the system_prompt was set to an empty
string (""), which pydantic-ai sends as {'role': 'system', 'content': ''}
to the LLM provider. Vertex AI (via litellm) rejects empty system
messages with a 400 error.
Fix by using an empty tuple () instead, which tells pydantic-ai to omit
the system message entirely. Also skip empty system messages from the
incoming request history, as some frontends (e.g., LibreChat title
generation) send {'role': 'system', 'content': ''}.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
system_promptwas set to""(empty string), causing pydantic-ai to send{'role': 'system', 'content': ''}to the LLM provider. Vertex AI rejects empty system messages with a 400 error.()so pydantic-ai omits the system message entirely when there's no RAG context.{'role': 'system', 'content': ''}.Test plan
test_convert_messages_skips_empty_system— verifies empty system messages are filteredtest_convert_messages_keeps_nonempty_system— verifies non-empty system messages are preservedtest_process_chat_request_no_rag— assertssystem_prompt == ()when no RAG contexttests/rag/test_engine.pypass