run-llama/llama_index · warning · ValueError

There are {len(self.selections)} selections, please use .ind

Error message

There are {len(self.selections)} selections, please use .inds.

What it means

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.

Source

Thrown at llama-index-core/llama_index/core/base/base_selector.py:28

MetadataType = Union[str, ToolMetadata]


class SingleSelection(BaseModel):
    """A single selection of a choice."""

    index: int
    reason: str


class MultiSelection(BaseModel):
    """A multi-selection of choices."""

    selections: List[SingleSelection]

    @property
    def ind(self) -> int:
        if len(self.selections) != 1:
            raise ValueError(
                f"There are {len(self.selections)} selections, please use .inds."
            )
        return self.selections[0].index

    @property
    def reason(self) -> str:
        if len(self.reasons) != 1:
            raise ValueError(
                f"There are {len(self.reasons)} selections, please use .reasons."
            )
        return self.selections[0].reason

    @property
    def inds(self) -> List[int]:
        return [x.index for x in self.selections]

    @property
    def reasons(self) -> List[str]:

View on GitHub (pinned to afd0fef371)

Solutions

  1. Guard before access: if len(result.selections) == 1: i = result.ind else: use result.selections / .inds.
  2. Use .selections[0].index / .reason directly and handle the empty list explicitly.
  3. If multiple picks are wrong, tighten the selector prompt to force exactly one choice (single-select phrasing, numbered options).

Example fix

# before
result = selector.select(prompt, choices)
i = result.ind  # ValueError when model picked 2 options

# after
result = selector.select(prompt, choices)
if len(result.selections) == 1:
    i = result.selections[0].index
else:
    inds = [s.index for s in result.selections]  # or re-ask / raise domain error
Defensive patterns

Strategy: type-guard

Validate before calling

def single_index(selection_result):
    sels = selection_result.selections
    if len(sels) == 1:
        return sels[0].index
    return None  # caller decides: re-ask, take first, or fail

Type guard

from llama_index.core.base.selector import MultiSelection

def is_single_selection(res) -> bool:
    return isinstance(res, MultiSelection) and len(res.selections) == 1

Try / catch

try:
    i = result.ind
except ValueError:
    i = result.selections[0].index if result.selections else None

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15). Data as JSON: /api/errors/0b866eb5cba847ee. Report an issue: GitHub.