run-llama/llama_index · error · ValueError

LLM did not return any tool calls for structured output. The

Error message

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.

What it means

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.

Source

Thrown at llama-index-core/llama_index/core/program/function_program.py:220

    def _parse_tool_outputs(
        self,
        agent_response: AgentChatResponse,
        allow_parallel_tool_calls: bool = False,
    ) -> Union[Model, List[Model]]:
        """
        Parse tool outputs.

        Validates that each tool output is actually a Pydantic model instance.

        Raises:
            ValueError: LLM did not return any tool calls, or a tool call
                failed (e.g. Pydantic validation error).
            TypeError: A tool call returned a non-BaseModel object.

        """
        if len(agent_response.sources) == 0:
            raise ValueError(
                "LLM did not return any tool calls for structured output. "
                "The model was expected to call a function to produce a "
                f"{self._output_cls.__name__} object, but instead returned "
                f"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."
            )

        outputs: List[Model] = []
        for source in agent_response.sources:
            raw = source.raw_output
            if source.is_error:
                # The tool call failed (e.g. Pydantic validation error).
                # Surface the original exception with context instead of
                # silently returning a string that will crash downstream.
                error_detail = str(source.exception) if source.exception else str(raw)

View on GitHub (pinned to afd0fef371)

Solutions

  1. Use a model/provider that honors tool_choice='required' for function calling.
  2. Switch to PydanticProgramMode.LLM to parse structured output from plain text.
  3. Strengthen the prompt so the model calls the function instead of answering in text.

When it happens

Trigger: Thrown at llama-index-core/llama_index/core/program/function_program.py:220 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/a052fc4fcbace737. Report an issue: GitHub.