run-llama/llama_index · error · ValueError
Invalid
Error message
Invalid
What it means
Poorly-named ValueError('Invalid') raised in the sync predict_and_call() flow: after executing the model's tool calls, if more than one tool output was produced while allow_parallel_tool_calls=False, the code cannot fold multiple results into a single AgentChatResponse and raises. It signals the model issued parallel tool calls even though they were disallowed.
Source
Thrown at llama-index-core/llama_index/core/llms/function_calling.py:258
call_tool_with_selection(tool_call, tools, verbose=verbose)
for tool_call in tool_calls
]
tool_outputs_with_error = [
tool_output for tool_output in tool_outputs if tool_output.is_error
]
if error_on_tool_error and len(tool_outputs_with_error) > 0:
error_text = "\n\n".join(
[tool_output.content for tool_output in tool_outputs]
)
raise ValueError(error_text)
elif allow_parallel_tool_calls:
output_text = "\n\n".join(
[tool_output.content for tool_output in tool_outputs]
)
return AgentChatResponse(response=output_text, sources=tool_outputs)
else:
if len(tool_outputs) > 1:
raise ValueError("Invalid")
elif len(tool_outputs) == 0:
return AgentChatResponse(
response=response.message.content or "", sources=tool_outputs
)
return AgentChatResponse(
response=tool_outputs[0].content, sources=tool_outputs
)
async def apredict_and_call(
self,
tools: Sequence["BaseTool"],
user_msg: Optional[Union[str, ChatMessage]] = None,
chat_history: Optional[List[ChatMessage]] = None,
verbose: bool = False,
allow_parallel_tool_calls: bool = False,
error_on_no_tool_call: bool = True,
error_on_tool_error: bool = False,View on GitHub (pinned to afd0fef371)
Solutions
- Pass allow_parallel_tool_calls=True if your agent can handle multiple results.
- Disable parallel tool calls at the provider level (e.g. OpenAI client with parallel_tool_calls=False) so the model returns one call per turn.
- Catch ValueError here and retry with a stronger instruction, or use a higher-level agent runner that normalizes multi-call responses.
Example fix
# before
resp = llm.predict_and_call(tools, user_msg='do both tasks') # model returns 2 tool calls -> ValueError('Invalid')
# after
resp = llm.predict_and_call(tools, user_msg='do both tasks', allow_parallel_tool_calls=True) Defensive patterns
Strategy: fallback
Validate before calling
try:
resp = llm.predict_and_call(tools, user_msg, allow_parallel_tool_calls=True)
except ValueError:
resp = llm.predict_and_call(tools, user_msg, allow_parallel_tool_calls=False) Try / catch
try:
resp = llm.predict_and_call(tools, user_msg, allow_parallel_tool_calls=False)
except ValueError as e:
if str(e) == 'Invalid':
resp = llm.predict_and_call(tools, user_msg, allow_parallel_tool_calls=True)
else:
raise Prevention
- Default to allow_parallel_tool_calls=True with models that batch calls
- Disable parallel calls at the provider (parallel_tool_calls=False) when you must have one call per turn
- Test agent tool flows against your specific model's multi-call behavior
When it happens
Trigger: llm.predict_and_call(tools, user_msg, allow_parallel_tool_calls=False) where the underlying model returns multiple tool_calls in one response — possible with models like GPT-4o that like parallel calls, or when the provider ignored the parallel-calls flag. get_tool_calls_from_response returns several selections, all execute, and len(tool_outputs) > 1 hits the branch.
Common situations: Agents built on predict_and_call with default flags against models that aggressively batch tool calls; provider config that enables parallel function calling at the API level (e.g. OpenAI parallel_tool_calls=True) contradicting the llama-index flag.
Related errors
- get_tool_calls_from_response is not supported by default.
- Max iterations of {max_iterations} reached! Either something
- No tool calls found, cannot aggregate results.
- Tool {tool.metadata.name} requires context. CodeActAgent onl
- Tool {tool.metadata.name} is not a FunctionTool. CodeActAgen
AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15).
Data as JSON: /api/errors/e8d306447ca4c612.
Report an issue: GitHub.