Return Value Contracts as the Primary CrewAI Tool Failure Signal in Production Learning Systems
Return-value contracts reveal silent tool failures invisible to final-output scoring.

To detect silent tool failures in production multi-agent pipelines, each tool’s return must be checked against an explicit contract, and what the agent does next must be recorded. In CrewAI, that return is the execution layer’s only feedback channel to the reasoning layer. Contract violations therefore provide a precise starting point for attributing failures and validating harness changes against the production traces that exposed them.
Why the tool return value is the only feedback channel the reasoning layer ever sees
A CrewAI tool call follows a narrow sequence. The agent calls a tool, the tool executes, and its return reaches the LLM as a string in the context window. The LLM then decides its next action from that context. Execution does not supply a separate channel through which the model can inspect what really happened.
The return must therefore be usable as a string. CrewAI converts non-string returns through json.dumps(), falling back to str() for types that cannot be serialized. Conversion can produce unreadable output without raising an error, leaving the reasoning layer with text that does not clearly communicate the execution result. A completed call and a useful observation are different conditions.
That distinction becomes decisive when a tool returns None or an empty string. The agent receives no useful evidence, but the reasoning loop does not necessarily stop. A descriptive error string would communicate a failed operation, while an empty return leaves the operation’s meaning unresolved. Because the channel is narrow and unforgiving, its contract is the right place to anchor observability.
How a silent return value turns a tool failure into an invisible hallucination
A tool that hits a 500 error can leave the agent with an empty or garbled result if its error handling does not return a descriptive string. The LLM may then supply a plausible continuation unsupported by retrieved data. The run can still look complete. Its final artifact may read coherently even though the execution layer supplied no evidence for part of it.
This differs structurally from a thrown exception. Exceptions surface immediately and are logged, while silent return violations can propagate through the reasoning chain without an equivalent failure signal. In a multi-agent crew, another agent may act on the unsupported response and carry the gap into later steps. An empty result does not always lead to a disastrous outcome. The workflow risks remaining active after its connection to ground truth has broken.
The EMPTY_RESULT subtype makes that risk especially clear. A tool returns a null data field or its equivalent, and the agent treats the absence as room to generate an answer. Nothing useful has crossed the execution boundary. Yet the trace may record a completed run, so completion alone cannot reliably show that the tool supplied the evidence the task needed.
Final-output scoring may identify a hallucination, leaving open which tool call introduced the gap, which agent acted on it, and what the return should have contained. Those are different diagnostic questions. An output score can establish that the result was wrong without preserving the chain needed to explain why.
Three return-value failure patterns that account for most tool-layer production breaks
Return-value contract violations fall into three patterns, which are schema drift, prompt-driven retry loops, and silent contract violations. Their symptoms can overlap, but their repair points differ. A parser that cannot consume a changed payload is not the same problem as an agent that cannot recognize success. Distinguishing those mechanisms prevents a visible retry from being treated as sufficient evidence that the tool itself is broken.
Schema drift begins when a third-party endpoint changes its schema, error codes, or rate limits while the CI mock still returns the old payload. The tool contract describes yesterday’s behavior. In the trace, a network-level success may precede a return that downstream parsing cannot handle, or argument-validation failures may fail to propagate as readable strings. The agent may be doing exactly what its instructions say even though they no longer fit what happens. The repair belongs at the contract and schema boundary.
Prompt-driven retry loops start when a tool description is vague or a success criterion is unclear, so the agent cannot tell that a return is valid. Repetition is the distinguishing trace signature. The agent invokes the same or similar tool calls five or more times in a row, producing repeated agent.trajectory.step entries and rising token-cost-per-trace. Without explicit termination conditions, this can continue until max_iter is exhausted or the run times out. CrewAI defaults max_iter to 20, but an iteration limit does not make the return legible. The tool description, success criterion, or termination rule needs to be fixed.
Silent contract violations include invented tool names, arguments supplied in the wrong shape, and misinterpreted tool output, none of which necessarily raises an error. They can also appear as delegation loops. One agent cannot act on a return and hands the task to another, which cannot act on it either. A guardrail rejection chain has a related shape when the rejection is not returned as a readable violation and the agent retries. Rising p99 latency, repeated delegation spans, and a climbing tool-retry rate without corresponding error logs point toward this family. Fixes for this family include readable failure returns and delegation rules.
Why scoring only the final crew output leaves these failures undetected
A final crew artifact compresses a multi-step process into one result. A research agent may hand incomplete context to a writer, a reviewer may approve an unsupported claim, or a tool-using agent may retry a slow API until cost spikes. The final response can still appear acceptable. A passing score on that response does not establish that the agents used the right tools or respected their role contracts.
A writer that begins fresh web searches mid-draft is no longer doing only the job its role rubric measures. The artifact may not reveal the departure. As a result, a role-level judgment requires evidence of the agent’s actual work.
The diagnostic chain needs per-agent scoring tied to tool calls. It must establish which agent acted, whether it stayed in role, what each tool returned, and how the agent used that return. ToolSelectionAccuracy, TaskCompletion, TrajectoryScore, and StepEfficiency make those distinctions visible when tracked per agent and per tool call. Their value is diagnostic, not decorative. They connect a quality judgment to the decisions and observations that produced it.
Cost and latency graphs remain necessary, but they answer a different question. They show accumulated consequences. A role-bleed pattern or retry loop can be visible in per-agent span data days before it becomes a cost anomaly. By the time the graph moves, many runs may already have been affected.
Treating return value contracts as first-class observability primitives
The practical response is to define each tool’s expected return as an explicit schema and validate production traces against it. The contract should distinguish a valid result, a failure return, and an empty or null result. Those meanings cannot remain implicit in an agent’s backstory. Trace analysis needs a stated expectation against which the actual string can be compared. Otherwise, it has text to inspect but no clear basis for labeling a violation.
Every tool call should capture five minimum fields, namely the tool name, the arguments passed, the raw return string, whether the return matched the expected schema, and the agent’s subsequent action. Each field serves a different diagnostic purpose. The name and arguments identify the attempted operation, while the raw string preserves what reached the reasoning layer. The schema check records whether that observation met the contract. The subsequent action shows whether the agent halted, retried, delegated, or continued on the basis of it.
A null data field or empty string should trigger a labeled EMPTY_RESULT signal and a readable failure return so that silence does not pass to the next step. The failure text should make the absence of data and the halt condition clear. That makes the event attributable to a particular call. It also separates “no usable data was returned” from a successful observation the agent can safely use.
Schema checks require the contract to be stored with the trace. An actual return that fails to match the expected schema can then appear as a parseable mismatch before it becomes an unsupported final answer. Retry detection uses a different comparison. When agent.trajectory.step entries repeat for the same tool but its return string stays the same, they reveal a prompt-ambiguity loop before max_iter is used up. The schema mismatch and repeated-step pattern identify different failures even when both eventually produce retries.
These signals give production usage a direct role in evaluation. Traces can flow into an analysis layer, be segmented by error type, and be attributed to a particular tool and return contract. The resulting cases become new evaluations.
Closing the loop from broken trace to verified fix without guessing which layer failed
A labeled violation is a starting point. Actionable attribution must identify the relevant harness layer, whether that is the prompt, tool schema, delegation rule, or workflow parameter. The visible symptom may occur several trajectory steps after the causal event. Span inspection alone is therefore insufficient. The investigation must follow the return through the trajectory and determine where the workflow first departed from its contract.
AgentDebugX’s 2026 Who&When benchmark found that even a multi-agent debugger built for the task had only 28.8% exact agent-and-step attribution accuracy. That result frames attribution as a search problem. A changed schema, an ambiguous prompt, and a faulty delegation rule can each provide a plausible explanation for a later failure. The trace must support one explanation and contradict the alternatives. The step where the error becomes visible is not necessarily the step that caused it.
For an engineering team, the workflow begins when eval-fail-rate-by-crew rises after a prompt or tool change. The engineer opens the failed traces, exports those runs as a regression dataset, and holds the release until ToolSelectionAccuracy and TaskCompletion recover. The production trace supplies the evidence. A rerun of CI cannot substitute for it when the mock still returns the old schema and omits the actual string that broke the contract.
Replay validation then tests the proposed harness change against those recorded runs, with tool outputs replayed and side effects sandboxed. A tightened tool description can address ambiguous success criteria, while a corrected return schema can address drift. The test is specific to the diagnosed violation. It checks whether the change resolves that failure without introducing new ones, rather than merely improving a synthetic case that resembles it.
Other changes follow the same attribution discipline. Explicit error strings for every failure path address silent violations, per-role tool allowlists address wrong-tool delegation, and explicit termination conditions in task descriptions address unresolved repetition. These changes are not interchangeable. Their justification must come from the observed mechanism, and their validation must use the return strings and trajectories that exposed it.
Return-value contracts, trace datasets, and replay results should therefore be saved for review and checked as closely as a code diff. A tool or prompt change then has an auditable validation history. The review can connect the broken return to the responsible harness layer, the proposed repair, and the replay result. That is the distinction between a plausible adjustment and a verified production fix.


