ValueError
llama_index.indices.response.response_synthesizer.ValueError
Stack trace
ValueError: Cannot synthesize response: received empty list of nodes
File "/path/to/llama_index/indices/response/response_synthesizer.py", line 123, in synthesize_response
raise ValueError("Cannot synthesize response: received empty list of nodes")
File "app.py", line 45, in main
response = response_synthesizer.synthesize_response(nodes)
Why it happens
The response synthesizer in LlamaIndex expects a non-empty list of document nodes to generate a combined answer. If the query or retrieval step returns no nodes, the synthesizer cannot proceed and raises this error. This often happens when the index is empty, the query is too restrictive, or the retriever configuration filters out all nodes.
Detection
Check the length of the nodes list before calling the synthesizer. Log or assert nodes is not empty to catch this condition early and avoid the exception.
Causes & fixes
The retriever returned no nodes because the index is empty or the query matched nothing.
Ensure the index is properly built and contains documents before querying. Use a broader query or adjust retriever parameters to return nodes.
Retriever filters or query parameters are too restrictive, filtering out all nodes.
Relax retriever filters or modify query parameters to allow some nodes to be returned.
Incorrect usage of the response synthesizer by passing an empty list explicitly.
Add a check before calling synthesize_response to skip or handle empty node lists gracefully.
Code: broken vs fixed
from llama_index import GPTListIndex, ResponseSynthesizer
index = GPTListIndex([]) # empty index
nodes = index.retrieve("some query")
response_synthesizer = ResponseSynthesizer()
response = response_synthesizer.synthesize_response(nodes) # triggers ValueError
print(response) import os
from llama_index import GPTListIndex, ResponseSynthesizer
# Assume OPENAI_API_KEY is set in environment
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
index = GPTListIndex([]) # empty index
nodes = index.retrieve("some query")
response_synthesizer = ResponseSynthesizer()
if not nodes:
print("No nodes found for the query. Cannot synthesize response.")
else:
response = response_synthesizer.synthesize_response(nodes) # safe call
print(response) Workaround
Wrap the synthesize_response call in try/except ValueError, and if caught, return a default message or fallback response instead of crashing.
Prevention
Design your retrieval pipeline to guarantee at least one node is returned for any query, or implement graceful handling of empty results before synthesis.