run-llama/llama_index · error · ValueError

Expected PydanticResponse, got {type(response)}

Error message

Expected PydanticResponse, got {type(response)}

What it means

Error "Expected PydanticResponse, got {type(response)}" thrown in run-llama/llama_index.

Source

Thrown at llama-index-core/llama_index/core/node_parser/relational/base_element.py:232

                next_context = self._get_context_lines(
                    str(elements[idx + 1].element), from_end=False, num_lines=3
                )
                if next_context:
                    table_context += "\n" + next_context

            table_context_list.append(table_context)

        async def _get_table_output(table_context: str, summary_query_str: str) -> Any:
            index = SummaryIndex.from_documents(
                [Document(text=table_context)],
            )
            query_engine = index.as_query_engine(llm=llm, output_cls=TableOutput)
            try:
                response = await query_engine.aquery(summary_query_str)
                if isinstance(response, PydanticResponse):
                    return response.response
                else:
                    raise ValueError(f"Expected PydanticResponse, got {type(response)}")
            except (ValidationError, ValueError):
                # There was a pydantic validation error, so we will run with text completion
                # fill in the summary and leave other fields blank
                query_engine = index.as_query_engine(llm=llm)
                response_txt = await query_engine.aquery(summary_query_str)
                return TableOutput(summary=str(response_txt), columns=[])

        summary_jobs = [
            _get_table_output(table_context, self.summary_query_str)
            for table_context in table_context_list
        ]
        summary_co = run_jobs(summary_jobs, workers=self.num_workers)
        summary_outputs = asyncio_run(summary_co)
        # Only assign table_output to table elements (not all elements)
        table_elements = [e for e in elements if e.type in ("table", "table_text")]
        for element, summary_output in zip(table_elements, summary_outputs):
            element.table_output = summary_output

View on GitHub (pinned to afd0fef371)

Solutions

  1. Ensure the LLM program returns a PydanticResponse for table extraction.
  2. Check the output parser configuration of the element extraction program.

When it happens

Trigger: Thrown at llama-index-core/llama_index/core/node_parser/relational/base_element.py:232 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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