{"record":{"id":"283c525042d9b11b","repo":"run-llama/llama_index","slug":"structured-output-extraction-failed-expected-a-s","errorCode":null,"errorMessage":"Structured output extraction failed: expected a {self._output_cls.__name__} instance but got {type(raw).__name__}: {raw!r}. This may indicate a bug in the LLM integration's tool call handling.","messagePattern":"Structured output extraction failed: expected a (.+?) instance but got (.+?): (.+?)\\. This may indicate a bug in the LLM integration's tool call handling\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/program/function_program.py","lineNumber":246,"sourceCode":"                \"output parsing instead.\"\n            )\n\n        outputs: List[Model] = []\n        for source in agent_response.sources:\n            raw = source.raw_output\n            if source.is_error:\n                # The tool call failed (e.g. Pydantic validation error).\n                # Surface the original exception with context instead of\n                # silently returning a string that will crash downstream.\n                error_detail = str(source.exception) if source.exception else str(raw)\n                raise ValueError(\n                    f\"Structured output extraction failed: the LLM's tool \"\n                    f\"call could not be parsed into \"\n                    f\"{self._output_cls.__name__}. \"\n                    f\"Error: {error_detail}\"\n                )\n            if not isinstance(raw, BaseModel):\n                raise TypeError(\n                    f\"Structured output extraction failed: expected a \"\n                    f\"{self._output_cls.__name__} instance but got \"\n                    f\"{type(raw).__name__}: {raw!r}. \"\n                    f\"This may indicate a bug in the LLM integration's \"\n                    f\"tool call handling.\"\n                )\n            outputs.append(cast(Model, raw))\n\n        if allow_parallel_tool_calls:\n            return outputs\n        else:\n            if len(outputs) > 1:\n                _logger.warning(\n                    \"Multiple outputs found, returning first one. \"\n                    \"If you want to return all outputs, set output_multiple=True.\"\n                )\n\n            return outputs[0]","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/program/function_program.py#L228-L264","documentation":"Error \"Structured output extraction failed: expected a {self._output_cls.__name__} instance but got {type(raw).__name__}: {raw!r}. This may indicate a bug in the LLM integration's tool call handling.\" thrown in run-llama/llama_index.","triggerScenarios":"Thrown at llama-index-core/llama_index/core/program/function_program.py:246 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Update the LLM integration so its tool call handling returns the output_cls instance.","Validate output_cls matches what the integration's function program produces."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}