run-llama/llama_index · error · ValueError

Unsupported output type: {type}

Error message

Unsupported output type: {type}

What it means

The helper that converts a pydantic program output into a SelectorResult accepts only SingleSelection or MultiSelection objects. Any other type produced by the structured-output program raises ValueError(f"Unsupported output type: {type(output)}"). This usually means the underlying program returned a wrapper (e.g. a Program/Result container) instead of the selection model itself.

Source

Thrown at llama-index-core/llama_index/core/selectors/pydantic_selectors.py:37

if TYPE_CHECKING:
    from llama_index.llms.openai import OpenAI  # pants: no-infer-dep


def _pydantic_output_to_selector_result(output: Any) -> SelectorResult:
    """
    Convert pydantic output to selector result.
    Takes into account zero-indexing on answer indexes.
    """
    if isinstance(output, SingleSelection):
        output.index -= 1
        return SelectorResult(selections=[output])
    elif isinstance(output, MultiSelection):
        for idx in range(len(output.selections)):
            output.selections[idx].index -= 1
        return SelectorResult(selections=output.selections)
    else:
        raise ValueError(f"Unsupported output type: {type(output)}")


class PydanticSingleSelector(BaseSelector):
    def __init__(self, selector_program: BasePydanticProgram) -> None:
        self._selector_program = selector_program

    @classmethod
    def from_defaults(
        cls,
        program: Optional[BasePydanticProgram] = None,
        llm: Optional["OpenAI"] = None,
        prompt_template_str: str = DEFAULT_SINGLE_PYD_SELECT_PROMPT_TMPL,
        verbose: bool = False,
    ) -> "PydanticSingleSelector":
        if program is None:
            program = FunctionCallingProgram.from_defaults(
                output_cls=SingleSelection,
                prompt_template_str=prompt_template_str,

View on GitHub (pinned to afd0fef371)

Solutions

  1. Make the custom program's output_cls exactly SingleSelection (single) or MultiSelection (multi)
  2. Map your custom model to SingleSelection/MultiSelection before passing to the converter
  3. Use the selector's from_defaults() program setup, which pins the correct output class

Example fix

# before
program = MyProgram(output_cls=MyCustomSelection)  # converter rejects it

# after
from llama_index.core.output_parsers.selection import SingleSelection
program = MyProgram(output_cls=SingleSelection)
Defensive patterns

Strategy: type-guard

Validate before calling

from llama_index.core.output_parsers.selection import SingleSelection, MultiSelection
assert isinstance(output, (SingleSelection, MultiSelection)), f"got {type(output)}"

Type guard

from llama_index.core.output_parsers.selection import SingleSelection, MultiSelection
def is_selection_output(output) -> bool:
    return isinstance(output, (SingleSelection, MultiSelection))

Prevention

When it happens

Trigger: Calling _pydantic_output_to_selectorresult (or Pydantic selectors whose program yields unexpected shapes) with a custom BasePydanticProgram whose output model is not exactly SingleSelection/MultiSelection — e.g. a user-defined pydantic class with selection-like fields.

Common situations: Swapping in a custom pydantic program (LLMStructuredCompletionProgram subclass or third-party program) whose output_cls differs from the expected selection schemas.

Related errors


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