{"record":{"id":"0b866eb5cba847ee","repo":"run-llama/llama_index","slug":"there-are-len-self-selections-selections-pleas","errorCode":null,"errorMessage":"There are {len(self.selections)} selections, please use .inds.","messagePattern":"There are (.+?) selections, please use \\.inds\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"llama-index-core/llama_index/core/base/base_selector.py","lineNumber":28,"sourceCode":"MetadataType = Union[str, ToolMetadata]\n\n\nclass SingleSelection(BaseModel):\n    \"\"\"A single selection of a choice.\"\"\"\n\n    index: int\n    reason: str\n\n\nclass MultiSelection(BaseModel):\n    \"\"\"A multi-selection of choices.\"\"\"\n\n    selections: List[SingleSelection]\n\n    @property\n    def ind(self) -> int:\n        if len(self.selections) != 1:\n            raise ValueError(\n                f\"There are {len(self.selections)} selections, please use .inds.\"\n            )\n        return self.selections[0].index\n\n    @property\n    def reason(self) -> str:\n        if len(self.reasons) != 1:\n            raise ValueError(\n                f\"There are {len(self.reasons)} selections, please use .reasons.\"\n            )\n        return self.selections[0].reason\n\n    @property\n    def inds(self) -> List[int]:\n        return [x.index for x in self.selections]\n\n    @property\n    def reasons(self) -> List[str]:","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/base/base_selector.py#L10-L46","documentation":"MultiSelection models an LLM selector's answer as a list of SingleSelection items. The convenience property .ind only makes sense when exactly one selection was made, so it raises ValueError when len(self.selections) != 1 and points you to .inds for the plural case.","triggerScenarios":"Using PydanticSingleSelector / LLMSingleSelector whose result is a MultiSelection (selectors always return MultiSelection even for one choice) and reading result.ind when the model returned 0 or 2+ selections; a selector prompt that lets the model pick multiple options against expectations.","commonSituations":"Assuming the selector returns a single choice object; multiple-choice prompts where the LLM selects several options; empty selections when the model declines to choose or output parsing fails.","solutions":["Guard before access: if len(result.selections) == 1: i = result.ind else: use result.selections / .inds.","Use .selections[0].index / .reason directly and handle the empty list explicitly.","If multiple picks are wrong, tighten the selector prompt to force exactly one choice (single-select phrasing, numbered options)."],"exampleFix":"# before\nresult = selector.select(prompt, choices)\ni = result.ind  # ValueError when model picked 2 options\n\n# after\nresult = selector.select(prompt, choices)\nif len(result.selections) == 1:\n    i = result.selections[0].index\nelse:\n    inds = [s.index for s in result.selections]  # or re-ask / raise domain error","handlingStrategy":"type-guard","validationCode":"def single_index(selection_result):\n    sels = selection_result.selections\n    if len(sels) == 1:\n        return sels[0].index\n    return None  # caller decides: re-ask, take first, or fail","typeGuard":"from llama_index.core.base.selector import MultiSelection\n\ndef is_single_selection(res) -> bool:\n    return isinstance(res, MultiSelection) and len(res.selections) == 1","tryCatchPattern":"try:\n    i = result.ind\nexcept ValueError:\n    i = result.selections[0].index if result.selections else None","preventionTips":["Remember selectors return MultiSelection even for single choices.","Branch on len(selections) before using .ind/.inds.","Phrase selector prompts to force exactly one choice when that is the contract."],"tags":["selector","pydantic","single-vs-multi","api-misuse"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}