{"record":{"id":"35f87d82c5b7745f","repo":"run-llama/llama_index","slug":"unsupported-output-type-type","errorCode":null,"errorMessage":"Unsupported output type: {type}","messagePattern":"Unsupported output type: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/selectors/pydantic_selectors.py","lineNumber":37,"sourceCode":"\nif TYPE_CHECKING:\n    from llama_index.llms.openai import OpenAI  # pants: no-infer-dep\n\n\ndef _pydantic_output_to_selector_result(output: Any) -> SelectorResult:\n    \"\"\"\n    Convert pydantic output to selector result.\n    Takes into account zero-indexing on answer indexes.\n    \"\"\"\n    if isinstance(output, SingleSelection):\n        output.index -= 1\n        return SelectorResult(selections=[output])\n    elif isinstance(output, MultiSelection):\n        for idx in range(len(output.selections)):\n            output.selections[idx].index -= 1\n        return SelectorResult(selections=output.selections)\n    else:\n        raise ValueError(f\"Unsupported output type: {type(output)}\")\n\n\nclass PydanticSingleSelector(BaseSelector):\n    def __init__(self, selector_program: BasePydanticProgram) -> None:\n        self._selector_program = selector_program\n\n    @classmethod\n    def from_defaults(\n        cls,\n        program: Optional[BasePydanticProgram] = None,\n        llm: Optional[\"OpenAI\"] = None,\n        prompt_template_str: str = DEFAULT_SINGLE_PYD_SELECT_PROMPT_TMPL,\n        verbose: bool = False,\n    ) -> \"PydanticSingleSelector\":\n        if program is None:\n            program = FunctionCallingProgram.from_defaults(\n                output_cls=SingleSelection,\n                prompt_template_str=prompt_template_str,","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/selectors/pydantic_selectors.py#L19-L55","documentation":"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.","triggerScenarios":"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.","commonSituations":"Swapping in a custom pydantic program (LLMStructuredCompletionProgram subclass or third-party program) whose output_cls differs from the expected selection schemas.","solutions":["Make the custom program's output_cls exactly SingleSelection (single) or MultiSelection (multi)","Map your custom model to SingleSelection/MultiSelection before passing to the converter","Use the selector's from_defaults() program setup, which pins the correct output class"],"exampleFix":"# before\nprogram = MyProgram(output_cls=MyCustomSelection)  # converter rejects it\n\n# after\nfrom llama_index.core.output_parsers.selection import SingleSelection\nprogram = MyProgram(output_cls=SingleSelection)","handlingStrategy":"type-guard","validationCode":"from llama_index.core.output_parsers.selection import SingleSelection, MultiSelection\nassert isinstance(output, (SingleSelection, MultiSelection)), f\"got {type(output)}\"","typeGuard":"from llama_index.core.output_parsers.selection import SingleSelection, MultiSelection\ndef is_selection_output(output) -> bool:\n    return isinstance(output, (SingleSelection, MultiSelection))","tryCatchPattern":null,"preventionTips":["Pin custom program output_cls to SingleSelection/MultiSelection","Map custom schemas to the standard selection models","Test selector programs against both expected types"],"tags":["selector","pydantic","structured-output"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}