BerriAI/litellm · error · ValueError
No query found in messages for RAG query
Error message
No query found in messages for RAG query
What it means
Raised when the RAG query pipeline cannot extract any query text from the request messages (no non-empty last user message), so there is nothing to retrieve with; the completion request is malformed for RAG mode.
Source
Thrown at litellm/rag/main.py:223
async def _execute_query_pipeline(
model: str,
messages: list[Any],
retrieval_config: dict[str, Any],
rerank: dict[str, Any] | None = None,
stream: bool = False,
**kwargs,
) -> ModelResponse:
"""
Execute the RAG query pipeline.
"""
# Extract router from kwargs - use it for completion if available
# to properly resolve virtual model names
router: Final[Router | None] = kwargs.pop("router", None)
# 1. Extract query from last user message
query_text: Final = RAGQuery.extract_query_from_messages(messages)
if not query_text:
raise ValueError("No query found in messages for RAG query")
# 2. Search vector store
with _suppressed_sub_call_billing():
search_response: Final = await litellm.vector_stores.asearch(
vector_store_id=retrieval_config["vector_store_id"],
query=query_text,
max_num_results=retrieval_config.get("top_k", 10),
custom_llm_provider=retrieval_config.get("custom_llm_provider", "openai"),
**kwargs,
)
search_provider: Final = retrieval_config.get("custom_llm_provider", "openai")
try:
search_cost = sum(
vector_store_search_cost(
model=search_provider if "/" in search_provider else None,
custom_llm_provider=search_provider,
response=search_response,View on GitHub (pinned to 77b7c6c40c)
Solutions
- Include a user message with query text in the messages array for the RAG query.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at litellm/rag/main.py:223 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/10538e90fb0cf3e1.
Report an issue: GitHub.