{"record":{"id":"a052fc4fcbace737","repo":"run-llama/llama_index","slug":"llm-did-not-return-any-tool-calls-for-structured-o","errorCode":null,"errorMessage":"LLM did not return any tool calls for structured output. The model was expected to call a function to produce a {self._output_cls.__name__} object, but instead returned plain text: {agent_response.response!r}. This can happen when the LLM provider does not honor tool_choice='required'. Consider using a different model or switching to PydanticProgramMode.LLM to use text-based output parsing instead.","messagePattern":"LLM did not return any tool calls for structured output\\. The model was expected to call a function to produce a (.+?) object, but instead returned plain text: (.+?)\\. This can happen when the LLM provider does not honor tool_choice='required'\\. Consider using a different model or switching to PydanticProgramMode\\.LLM to use text-based output parsing instead\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/program/function_program.py","lineNumber":220,"sourceCode":"\n    def _parse_tool_outputs(\n        self,\n        agent_response: AgentChatResponse,\n        allow_parallel_tool_calls: bool = False,\n    ) -> Union[Model, List[Model]]:\n        \"\"\"\n        Parse tool outputs.\n\n        Validates that each tool output is actually a Pydantic model instance.\n\n        Raises:\n            ValueError: LLM did not return any tool calls, or a tool call\n                failed (e.g. Pydantic validation error).\n            TypeError: A tool call returned a non-BaseModel object.\n\n        \"\"\"\n        if len(agent_response.sources) == 0:\n            raise ValueError(\n                \"LLM did not return any tool calls for structured output. \"\n                \"The model was expected to call a function to produce a \"\n                f\"{self._output_cls.__name__} object, but instead returned \"\n                f\"plain text: {agent_response.response!r}. \"\n                \"This can happen when the LLM provider does not honor \"\n                \"tool_choice='required'. Consider using a different model or \"\n                \"switching to PydanticProgramMode.LLM to use text-based \"\n                \"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)","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/program/function_program.py#L202-L238","documentation":"Error \"LLM did not return any tool calls for structured output. The model was expected to call a function to produce a {self._output_cls.__name__} object, but instead returned plain text: {agent_response.response!r}. This can happen when the LLM provider does not honor tool_choice='required'. Consider using a different model or switching to PydanticProgramMode.LLM to use text-based output parsing instead.\" thrown in run-llama/llama_index.","triggerScenarios":"Thrown at llama-index-core/llama_index/core/program/function_program.py:220 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use a model/provider that honors tool_choice='required' for function calling.","Switch to PydanticProgramMode.LLM to parse structured output from plain text.","Strengthen the prompt so the model calls the function instead of answering in text."],"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-15T17:31:12.345Z"}