How do I detect failures in AI agent tool calls?
Summary
- Tool-call failures are often silent: an agent tends to retry, guess and work around a broken tool, so the task still finishes while tokens and wait time pile up. Final answers alone won't show it.
- Trace every tool invocation as a span with the tool name, arguments, result, status and error type, so you can filter failed calls and replay the run behind each one.
- Watch for three classes of failure: hard errors (exceptions, HTTP or JSON-RPC error codes, policy denials), soft errors (wrong tool, wrong or missing arguments, malformed output) and waste (redundant or repeated calls).
- On Databricks, Unity Gateway records MCP tool calls in a unified trace table in OpenTelemetry format (Beta). MLflow Tracing captures tool spans inside your own agent code, and MLflow judges such as ToolCallCorrectness and ToolCallEfficiency score tool use automatically.
How do I detect failures in AI agent tool calls?
To detect tool-call failures, trace every tool invocation as a span that records its arguments, result, status and error type. Then query those spans for errors, repeats and bad arguments. Watching final answers won't surface them. A Databricks engineering team that investigated its own agents found that when tools misbehave, the calling agent "rarely fails loudly. Instead, it retries, guesses, and eventually works around the problem." So treat tool calls as first-class telemetry, and pair hard error signals with automated judges that check whether the agent called the right tool in the right way.
What counts as a tool-call failure?
| Failure type | What it looks like | Signal to capture |
|---|---|---|
| Hard error | The tool raises an exception or returns an HTTP or JSON-RPC error | Span status, error type, status codes |
| Policy denial | A guardrail blocks the call before or after it runs | Policy name and enforced action |
| Bad arguments | A required argument is missing, or a value has the wrong shape | Tool arguments plus the error message returned |
| Wrong tool | The agent picks a tool that can't answer the question | Trace-level judge against expected tool calls |
| Redundant calls | The same call repeats, or the agent loops | Identical calls per trace or session |
| Silent recovery | The agent works around a failure and the task completes | Repeat errors per session, turns spent recovering |
The last two rows are the ones teams miss: a correct final answer can still hide a broken tool.
How Databricks approaches tool-call failure detection
Gateway layer: Unity Gateway. MCP servers registered in Unity Catalog are governed as MCP services, and their traffic flows through Unity Gateway. The unified trace table (Beta) captures every request and response across Unity Gateway model and MCP services in one Unity Catalog table in OpenTelemetry format. MCP spans carry gen_ai.tool.name, gen_ai.tool.call.arguments, gen_ai.tool.call.result and rpc.response.status_code, which the docs call the primary MCP failure signal. They also carry error.type, with values such as policy_deny, upstream_error or internal_error, so you can separate a blocked call from a broken server. A query for failed tool spans looks like this:
SELECT trace_id,
attributes:`gen_ai.tool.name`::string AS tool,
attributes:`error.type`::string AS error_type,
attributes:`rpc.response.status_code` AS rpc_code
FROM <catalog>.<schema>.<table_name>
WHERE attributes:`mlflow.spanType`::string = 'TOOL'
AND status.code = 'STATUS_CODE_ERROR'
AND time >= current_timestamp() - INTERVAL 1 DAY;
Filter by trace_id to replay every step of the failed run, or let Genie Code write the query. Without Beta features, the system.ai_gateway.usage table still records mcp_metadata.tool_name and status_code for MCP requests.
Agent layer: MLflow Tracing. For tools that run inside your own code, decorate them with @mlflow.trace(span_type=SpanType.TOOL) or use autologging for your framework. When a traced function raises an exception, MLflow marks the span as failed and records the exception details on the span. For traces stored in Unity Catalog, mlflow.search_traces() can filter on span type and span status.
Quality layer: judges and monitoring. Hard errors are the easy part. The built-in ToolCallCorrectness judge checks whether the tool calls and arguments were correct for the query (it needs expected values), and ToolCallEfficiency flags redundant calls. ConversationalToolCallEfficiency does the same across a whole session. Production monitoring (Beta) runs the same scorers on a sample of live traces. MLflow Issue Detection (Beta) groups recurring problems across traces, such as an agent that omits a required argument and makes a booking tool fail.
A practical detection workflow
- Route and instrument. Send MCP traffic through Unity Gateway and trace in-process tools with MLflow, so every call produces a span.
- Alert on hard errors by tool. Traces in Unity Catalog are Delta tables, so AI/BI dashboards and alerts run on them directly.
- Rank by repeat rate. A tool the agent hits again and again in one session matters most.
- Fix the tool contract. The Databricks investigation found recovery cost tracked error-message quality. Return self-documenting errors, and accept the reasonable variations a model sends (coerce a list to a string, default an omitted parameter) instead of crashing.
- Lock it in. Add a judge or issue monitor so the failure can't quietly come back.
FAQs
Why don't my agent's final answers show tool failures?
Agents often recover by retrying or trying another route, so the answer can be right even when a tool failed along the way. Only the intermediate tool spans show it.
How do I tell a policy denial from a broken tool?
In the Unity Gateway unified trace table, the error.type attribute on MCP spans distinguishes policy_deny from failures such as upstream_error or internal_error. When a policy blocks a request, the root span also records the policy name and its enforced action.
Do I need to change agent code to trace MCP tool calls?
Not for calls routed through Unity Gateway. Once a metastore admin enables the unified trace table, gateway traffic is logged automatically. Tools that run inside your own process still need MLflow Tracing or OpenTelemetry instrumentation.
How do I catch a tool call that succeeded but was wrong?
Status codes can't catch it, so use an evaluator. The ToolCallCorrectness judge compares the agent's tool calls and arguments with expected ones, and custom judges can check domain-specific rules.
The information provided herein is for general informational purposes only and may not reflect the most current product capabilities or configurations.