run-llama/llama_index · error · ValueError
Invalid result.ind: {result.ind}
Error message
Invalid result.ind: {result.ind} What it means
SQLJoinQueryEngine._query uses a single selector with two choices: ind 0 routes to SQL+other join synthesis, ind 1 routes to the other query engine. Any other index is a programming/selector error and raises ValueError(f"Invalid result.ind: {result.ind}").
Source
Thrown at llama-index-core/llama_index/core/query_engine/sql_join_query_engine.py:347
"""Query and get response."""
# TODO: see if this can be consolidated with logic in RouterQueryEngine
metadatas = [self._sql_query_tool.metadata, self._other_query_tool.metadata]
result = self._selector.select(metadatas, query_bundle)
# pick sql query
if result.ind == 0:
if self._verbose:
print_text(f"Querying SQL database: {result.reason}\n", color="blue")
logger.info(f"> Querying SQL database: {result.reason}")
return self._query_sql_other(query_bundle)
elif result.ind == 1:
if self._verbose:
print_text(
f"Querying other query engine: {result.reason}\n", color="blue"
)
logger.info(f"> Querying other query engine: {result.reason}")
return self._other_query_tool.query_engine.query(query_bundle)
else:
raise ValueError(f"Invalid result.ind: {result.ind}")
async def _aquery(self, query_bundle: QueryBundle) -> RESPONSE_TYPE:
# TODO: make async
return self._query(query_bundle)
View on GitHub (pinned to afd0fef371)
Solutions
- Use a function-calling LLM with the default PydanticSingleSelector for reliable 0/1 output
- Do not override the selector with extra choices; SQLJoinQueryEngine passes is_multi=False and expects exactly two options
- Catch ValueError around query() and retry once, or route manually to one engine
Example fix
// before
join_engine = SQLJoinQueryEngine(
sql_tool, other_tool,
selector=LLMSingleSelector.from_defaults(llm=weak_llm),
)
// after
join_engine = SQLJoinQueryEngine(sql_tool, other_tool) # default selector from Settings.llm
# ensure Settings.llm is a function-calling model, e.g. OpenAI(model="gpt-4o-mini") Defensive patterns
Strategy: retry
Try / catch
try:
resp = join_engine.query(q)
except ValueError as e:
if "Invalid result.ind" in str(e):
resp = join_engine.query(q) # retry: selector output is nondeterministic
else:
raise Prevention
- Use the default selector with a function-calling LLM
- Do not customize selector choices for SQLJoinQueryEngine — exactly two options are expected
- Wrap routing queries with one retry to absorb rare invalid indices
When it happens
Trigger: The selector LLM returns an index outside {0, 1} (e.g. 2+) when routing in SQLJoinQueryEngine, typically with LLMSingleSelector on a weak model or a custom selector misconfigured with extra choices.
Common situations: Non-deterministic LLM output failing the two-choice format; custom selector prompt that lists more than two options; small local models.
Related errors
- Failed to select query engine
- sql_query_tool.query_engine must be an instance of BaseSQLTa
- Unknown tool name: {tool_call_result.tool_name}
- There are {len(self.selections)} selections, please use .ind
- There are {len(self.reasons)} selections, please use .reason
AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15).
Data as JSON: /api/errors/ec49c3d0eaadcd4c.
Report an issue: GitHub.