Skip to content

fix(rag): avoid empty system messages that crash Vertex AI#426

Merged
basnijholt merged 1 commit intomainfrom
fix/empty-system-prompt-vertex-ai
Feb 12, 2026
Merged

fix(rag): avoid empty system messages that crash Vertex AI#426
basnijholt merged 1 commit intomainfrom
fix/empty-system-prompt-vertex-ai

Conversation

@basnijholt
Copy link
Owner

Summary

  • When no RAG context is retrieved, the system_prompt was 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.
  • Changed the default to an empty tuple () so pydantic-ai omits the system message entirely when there's no RAG context.
  • Also filter out empty system messages from incoming request history, as some OpenAI-compatible frontends (e.g., LibreChat title generation) send {'role': 'system', 'content': ''}.

Test plan

  • Added test_convert_messages_skips_empty_system — verifies empty system messages are filtered
  • Added test_convert_messages_keeps_nonempty_system — verifies non-empty system messages are preserved
  • Updated test_process_chat_request_no_rag — asserts system_prompt == () when no RAG context
  • All 11 tests in tests/rag/test_engine.py pass

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': ''}.
@basnijholt basnijholt merged commit 10de384 into main Feb 12, 2026
8 of 10 checks passed
@basnijholt basnijholt deleted the fix/empty-system-prompt-vertex-ai branch February 12, 2026 06:37
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.

1 participant