Skip to content

Fix AI agent tool call failures in production

To fix tool call failures in production, record every tool call as a named span, score the outcome against what the user actually wanted, block out-of-scope calls before they execute, and trace recurring failures back to the prompt or configuration that caused them.

By Arun PrasadPublished

Why tool call failures are hard to catch

Standard infrastructure monitoring tells you the tool responded. It doesn't tell you whether the agent called the right tool, passed the right arguments, or accomplished what the user asked.

This gap matters because AI agents don't fail like normal software. A tool can return a 200 and the task can still fail. Your observability dashboard shows green, your error rate is flat, and somewhere a user got a wrong result or an action they didn't ask for. You often find out from a support ticket, not a metric.

A common concern is that there's no reliable way to control what tool actions an agent will take once it's autonomous. Without visibility into each tool call, the only option is to restrict what the agent can do, often more than necessary.

To catch this class of failure you need to track outcomes against what the user actually wanted, not just whether each span completed. The five steps below show how to do that.

Step 1: Capture every tool call as a named span

A tool call that isn't recorded as a named step is invisible to any downstream analysis. If you're recording only the final response, you can see that something went wrong but not which tool call caused it or what arguments the model passed.

  • Python SDK, attaches a handler to your framework and captures full trajectories: model calls, tool calls, retrieval steps, handoffs and errors as individual spans.
  • Zero-code proxy, change the base URL in your client config to route through PRISM, and add your PRISM key in the X-PRISMtrace-Key header in the same config. Records prompts, completions, latency and tokens, with inline guardrails.
  • OpenTelemetry, set two environment variables; no PRISM SDK required.
  • HTTP, one POST per exchange; works for TypeScript, Go, Java or any framework the SDK doesn't cover.

For full tool call trajectories, the Python SDK gives you the most detail. Install it with:

Example

Example · text
pip install "prismtrace-sdk>=0.5.1"

Then import prismtrace and attach the handler for your framework (LangChain, LangGraph, Google ADK, LiteLLM, or the OpenAI Agents SDK). Each tool call, retrieval step and handoff appears as its own span in the trace.

If you're using TypeScript, Go or Java, the HTTP path records the same exchange with one POST after each response. For individual tool call spans, switch to the OpenTelemetry path.

Step 2: Read the trace to find which tool call failed and why

To find which tool call failed, examine the full trace sequence in Agent Runs and look for patterns where tool choice doesn't match the user's stated intent or where the same tool retries without resolving the underlying problem.

A span that looks fine in isolation can still represent a wrong tool choice, the tool ran, it returned a result, but the model chose it for the wrong reason. That only becomes visible when you see the full sequence alongside the user's original request and the final response.

The Traces view adds scores, guardrail flags and trajectory steps for the same run. A low satisfaction score on a trace that completed all its spans without errors is often the first signal that the tool sequence did the right steps for the wrong goal.

Look for these patterns in the trace:

  • A tool is called before the model has enough context to know what the user wants.
  • The same tool is called two or three times with slightly different arguments (retry loops that don't resolve the underlying problem).
  • The tool called doesn't match the intent recorded for the conversation.
  • The arguments passed contain a default or placeholder value rather than something drawn from the user's message.

Step 3: Detect when the agent picks the wrong tool or calls one out of scope

You detect wrong or out-of-scope tool calls by scoring outcomes against the user's intent and by running deterministic rules scoped to each tool type.

Automatic scoring runs on every trace as it arrives, at no credit cost. Each trace gets a customer satisfaction score (0–100), a response quality score, and the intent detected for that conversation. When either score falls below 40 or the reply looks like a hallucination, the trace is flagged for review with a one-line reason. A wrong tool choice often shows up as a low satisfaction score alongside an intent that doesn't match what the tool does. Each plan has a daily ceiling on automatic LLM scoring, 100 traces on Free, 200 on Builder.

Evaluator rules let you be more specific.

  • Deterministic rules run on every session with no model and no sampling. Use these to check whether a tool call appears in a trace where it shouldn't, or whether a required tool was skipped.
  • LLM-as-judge rules apply a rubric where {input} is the user's last message, {output} is the agent's final answer and {context} is what the retrieval and tool steps returned. Use these to check whether the tool called matches the user's stated intent.

Scope each evaluator to a specific agent and tool category rather than writing one rule for everything. That way a wrong tool call in one workflow doesn't get masked by clean results in another.

Step 4: Block or flag tool calls before they cause harm

To block tool calls before they cause harm, use the Tool Firewall to check each call before execution.

Before each tool call, your agent sends a check to POST /api/tool-firewall/check; PRISM answers allow, deny, or ask for approval. A denied call stops before the action runs.

Note: the published SDK does not call the Firewall yet. Your application code makes the HTTP call before each tool execution.

On Builder, watch mode records every call and what the rules would have done, useful for tuning rules before you turn on enforcement.

On Growth and above, enforcement is live: a denied call stops the action, and Knowledge Base fact-checking can verify that the tool's output matches what your documents say is true.

Detection after the fact is useful for finding patterns. For high-stakes tool calls, booking something, moving money, sending a message, you want to stop the action before it completes, not analyze it afterward. That's the distinction between the evaluator rules in Step 3 and the Tool Firewall here: one surfaces a pattern, the other prevents the action.

Step 5: Cluster failures, fix the cause, and verify the fix held

To cluster failures and fix the cause, group recurring tool call failures into Issues and use Root Cause analysis to trace each failure back to the responsible component.

Recurring tool call failures are grouped into Issues, one per kind of mistake, each with a diagnosis, the suspect files and a list of fix attempts. Root Cause analysis clusters the failing traces and traces each back toward the responsible component: the prompt, missing source, retrieval, stale state, tool choice, parameter, guardrail or workflow step.

A root-cause fix attempt (5 credits) drafts a patch, replays the failing traces against it and opens a draft pull request for the team to review. PRISM opens that pull request only when you've turned remediation on, granted write access, and at least 80% of replays pass. A person reviews and merges it, nothing ships without human sign-off.

After the merge, PRISM compares pass rates for the 7 days before and the 7 days after, so you can see whether the fix held or the failure came back in a different form.

How this looks in production

Here's an illustrative example of how this plays out in PRISM. The scenario and figures below are sample data for illustration.

An agent handles travel inquiries. A user asks: "What does it cost to fly from Chicago to Denver next Tuesday?" The agent calls a book_flight tool instead of a get_prices tool. The booking tool returns a confirmation. The trace shows a 200 on every span.

In the Traces view, the trace has a satisfaction score of 22. The intent recorded is "price inquiry". The trajectory shows one span: book_flight with a date, an origin and a destination as arguments. No get_prices call appears anywhere in the sequence.

More sessions with the same low satisfaction score appear, each showing the same intent label and the same wrong tool choice.

The Sessions view shows they all share the same pattern: a price question followed by a booking action.

Root Cause groups the failing traces into one Issue and a fix attempt drafts a prompt change that makes the distinction between price inquiry and booking explicit.

The failing traces are replayed against the patch. 84% pass. PRISM opens a draft pull request. An engineer reviews the diff, approves it, and merges.

Seven days later the before/after comparison shows the "tool called outside stated intent" pattern dropped from the top Issue to undetected. The satisfaction scores for price-inquiry sessions rose.

The trace didn't show a failure. The scores, the intent detection and the trajectory together did.

Connect your agent and see your own tool call spans in PRISM, start free.

Common mistakes

1. Treating a 200 HTTP status as proof the task succeeded. A tool returning success means the tool ran. It doesn't mean the agent called the right tool, passed the right arguments, or accomplished what the user wanted. Score outcomes, satisfaction, response quality, intent match, not just span status.

2. Recording only the final response and losing the tool call sequence. If you send one HTTP POST per exchange with only the prompt and response, you can tell that something went wrong but not which step caused it. Use the Python SDK to send full trajectories: model calls, tool calls, retrieval steps, handoffs and errors as individual spans. That's what makes root cause possible.

3. Writing one evaluator for all tools instead of scoping each rule to a specific agent and tool type. A single broad rule gets noisy quickly. The same tool call may be expected in one workflow and a violation in another. Evaluator runs let you pick the agent, the time window and the trace set before anything is charged (1 credit per trace scored). Scope each rule to match the behavior you're actually checking.

4. Fixing the tool's error handling instead of the prompt that chose the wrong tool. The tool's error handling usually isn't the problem. Root Cause in PRISM traces failures back to the responsible component: the prompt, missing source, retrieval, stale state, tool choice, parameter, guardrail or workflow step, so you fix the right thing.

How do you detect when an AI agent picks the wrong tool or calls a tool out of scope?

Add a deterministic evaluator rule scoped to the specific agent and tool type you're watching, and pair it with automatic intent detection.

Every trace that arrives in PRISM gets an intent label as part of automatic scoring. When the detected intent for a conversation doesn't match the category of tool the agent called, the satisfaction score often falls below 40 and the trace is flagged for review. Low satisfaction scores on traces where every span completed successfully are another indicator, they often correspond to a tool that ran but did the wrong thing.

Deterministic rules run on every session, no sampling, no model, same verdict for the same input. They surface a pattern consistently, as soon as it appears in your traces.

For subtler cases, where the tool name is correct but the arguments are wrong for the user's intent, an LLM-as-judge rule applies a rubric that reads {input} (the user's message), {output} (the agent's answer) and {context} (what the retrieval and tool steps returned) together, so it can catch the mismatch even when no single span looks wrong in isolation.

What causes tool call failures in production AI agents and how do you find the root cause?

Common causes include an ambiguous system prompt, a missing or poorly written tool description, bad argument construction from incomplete context, stale retrieval state, and retry loops that call the same failing tool repeatedly.

An ambiguous system prompt gives the model competing instructions, so it resolves the ambiguity by choosing an action the user didn't intend.

A poorly written tool description means the model selects a tool based on a name and description that fit more than one intent, so it sometimes picks the wrong one.

Bad argument construction happens when the model builds a tool call from partial information, filling gaps with defaults or guesses that make the call technically valid but practically wrong.

Stale retrieval state occurs when a retrieval step returns context from an earlier turn or a cached result, and the model constructs a tool call based on information that no longer applies.

Retry loops that call the same failing tool repeatedly amplify a transient error into multiple wrong actions.

Finding the root cause means looking at the full trace sequence, not just the failing span. Root Cause analysis in PRISM clusters failing traces by kind, then traces each cluster back toward the responsible component: the prompt, missing source, retrieval, stale state, tool choice, parameter, guardrail or workflow step. Each Issue comes with a diagnosis and the suspect files, so you're looking at the cause rather than the symptom.

How do you prevent AI agents from taking actions they shouldn't?

The Tool Firewall checks each call before it executes, so the agent never completes an out-of-scope action.

Before each tool execution, your agent sends a check to POST /api/tool-firewall/check. PRISM answers allow, deny, or ask for approval. A denied call stops before the action runs. This is an enforcement layer, not a detection layer: the action doesn't happen and then get flagged, it doesn't happen at all.

For agents that take consequential actions, booking flights, making purchases, sending communications, moving money, that distinction matters. Detection after the fact can tell you the problem exists; prevention stops the harm.

Before launch, simulated-user testing runs realistic conversations against your agent. For agents that call tools, PRISM grades what the agent did, not just what it said, against your documents and rules.

See your tool call failures before your users do

Connect your agent to PRISM and get a full trace of every tool call, score and intent in production.

Free to start, 100 credits each month.