{"record":{"id":"ec49c3d0eaadcd4c","repo":"run-llama/llama_index","slug":"invalid-result-ind-result-ind","errorCode":null,"errorMessage":"Invalid result.ind: {result.ind}","messagePattern":"Invalid result\\.ind: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/query_engine/sql_join_query_engine.py","lineNumber":347,"sourceCode":"        \"\"\"Query and get response.\"\"\"\n        # TODO: see if this can be consolidated with logic in RouterQueryEngine\n        metadatas = [self._sql_query_tool.metadata, self._other_query_tool.metadata]\n        result = self._selector.select(metadatas, query_bundle)\n        # pick sql query\n        if result.ind == 0:\n            if self._verbose:\n                print_text(f\"Querying SQL database: {result.reason}\\n\", color=\"blue\")\n            logger.info(f\"> Querying SQL database: {result.reason}\")\n            return self._query_sql_other(query_bundle)\n        elif result.ind == 1:\n            if self._verbose:\n                print_text(\n                    f\"Querying other query engine: {result.reason}\\n\", color=\"blue\"\n                )\n            logger.info(f\"> Querying other query engine: {result.reason}\")\n            return self._other_query_tool.query_engine.query(query_bundle)\n        else:\n            raise ValueError(f\"Invalid result.ind: {result.ind}\")\n\n    async def _aquery(self, query_bundle: QueryBundle) -> RESPONSE_TYPE:\n        # TODO: make async\n        return self._query(query_bundle)\n","sourceCodeStart":329,"sourceCodeEnd":352,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/query_engine/sql_join_query_engine.py#L329-L352","documentation":"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}\").","triggerScenarios":"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.","commonSituations":"Non-deterministic LLM output failing the two-choice format; custom selector prompt that lists more than two options; small local models.","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"],"exampleFix":"// before\njoin_engine = SQLJoinQueryEngine(\n    sql_tool, other_tool,\n    selector=LLMSingleSelector.from_defaults(llm=weak_llm),\n)\n\n// after\njoin_engine = SQLJoinQueryEngine(sql_tool, other_tool)  # default selector from Settings.llm\n# ensure Settings.llm is a function-calling model, e.g. OpenAI(model=\"gpt-4o-mini\")","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    resp = join_engine.query(q)\nexcept ValueError as e:\n    if \"Invalid result.ind\" in str(e):\n        resp = join_engine.query(q)  # retry: selector output is nondeterministic\n    else:\n        raise","preventionTips":["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"],"tags":["sql","join","selector","llm-output"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}