[BUG] Truncated tool-call input is silently "repaired" and executed with a wrong answer
Description
When an agent equipped with a search tool generates malformed tool call parameters (e.g., truncated JSON), the system executes the tool without raising warnings or triggering retries. This silent failure ultimately leads to incorrect responses.
Steps to Reproduce
Run the following code, and will see the wrong answer.
from __future__ import annotations
from crewai.llms.base_llm import BaseLLM
from crewai import Agent
from crewai.tools import tool
class ScriptedLLM(BaseLLM):
"""Returns scripted responses in order (repeating the last one)."""
def __init__(self, script=None, **kwargs):
super().__init__(model="scripted", **kwargs)
self.script = list(script or [])
self.seen: list = []
def call(self, messages, tools=None, callbacks=None, available_functions=None, from_task=None, from_agent=None, **kwargs):
self.seen.append(messages)
return self.script[min(len(self.seen) - 1, len(self.script) - 1)]
@tool("search")
def search(query: str) -> str:
"""Search notes."""
if query == "XYZ":
return "XYZ is a person."
elif query == "XYZ.com":
return "XYZ.com is a website."
return "Unknown query."
raw = '{"query": "XYZ' # An invalid tool input
llm = ScriptedLLM(
[
f"Thought: search.\nAction: search\nAction Input: {raw}",
"Final Answer: done",
]
)
agent = Agent(role="tester", goal="test", backstory="b", llm=llm, tools=[search], allow_delegation=False, max_iter=3)
agent.kickoff("Search for XYZ.com, tell me what it is.")
Expected behavior
The agent should receive an explicit error message rather than silently repairing truncated input, as automatic correction may introduce inaccuracies and lead to erroneous outputs.
Screenshots/Code snippets
invalid input {"query": "XYZ is repaired automatically to {"query": "XYZ"}, however the user want to ask information about website XYZ.com
Operating System
Ubuntu 22.04
Python Version
3.11
crewAI Version
1.15.28
crewAI Tools Version
1.15.28
Virtual Environment
Conda
Evidence
Possible Solution
Add reject to the invalid input in "_validate_tool_input", and also return agent the error message to let it fix the input and retry call the tool.
Additional context
None
I ran a small known-answer set on this with the same scripted LLM pattern as your repro, on crewai 1.15.28. For each input I wrote the expected result first: valid JSON should reach the tool unchanged, and malformed JSON should not reach the tool at all, with an error going back to the agent.
| Case | Action Input | Expected | Tool actually received | Error back to agent |
|---|---|---|---|---|
| K1 | {"query": "XYZ.com"} |
XYZ.com | XYZ.com | no (correct) |
| K2 | {"query": "XYZ |
not called | XYZ | no |
| K3 | {"query": "XYZ.com |
not called | XYZ.com | no |
| K4 | {"query": "XYZ.com" |
not called | XYZ.com | no |
| K5 | {"query": "XY |
not called | XY | no |
| K6 | {"qu |
not called | not called | yes |
So the repair runs whenever there is a value to salvage, not only in your XYZ case. K2 and K5 execute a wrong, shorter query and the agent never learns the input was cut. K3 and K4 happen to land on the right value, but they are repaired just as silently. The only case that errors (K6) is the one where nothing can be salvaged, and that error message is exactly what the other four should return as well.
The script is about 80 lines, uses no API key, and runs in a few seconds. Happy to run it against a fix branch, or add it as a test if a maintainer wants that.
Adam
This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue was closed because it has been stalled for 5 days with no activity.