By Sagar Shankaran, Founder of CallSphere
Master the full spectrum of failure modes in AI agent systems — from LLM hallucinations and tool execution errors to network timeouts and business logic violations — with structured handling strategies for each category.
Key takeaways
Traditional software fails in predictable ways — null pointers, type mismatches, connection refused. AI agents introduce an entirely new dimension of failure because they rely on probabilistic models, external APIs with variable latency, and tool integrations that can break in subtle ways. A robust agent needs a structured error taxonomy so every failure is caught, categorized, and handled appropriately.
Without a taxonomy, teams end up with a patchwork of try/except blocks that swallow important errors and let destructive ones pass through silently.
Every error in an AI agent system falls into one of four categories, each demanding a different response strategy.
flowchart LR
INPUT(["User intent"])
PARSE["Parse plus<br/>classify"]
PLAN["Plan and tool<br/>selection"]
AGENT["Agent loop<br/>LLM plus tools"]
GUARD{"Guardrails<br/>and policy"}
EXEC["Execute and<br/>verify result"]
OBS[("Trace and metrics")]
OUT(["Outcome plus<br/>next action"])
INPUT --> PARSE --> PLAN --> AGENT --> GUARD
GUARD -->|Pass| EXEC --> OUT
GUARD -->|Fail| AGENT
AGENT --> OBS
style AGENT fill:#4f46e5,stroke:#4338ca,color:#fff
style GUARD fill:#f59e0b,stroke:#d97706,color:#1f2937
style OBS fill:#ede9fe,stroke:#7c3aed,color:#1e1b4b
style OUT fill:#059669,stroke:#047857,color:#fff
These originate from the language model itself — rate limits, context length exceeded, malformed output, or hallucinated tool calls.
Hear it before you finish reading
Talk to a live CallSphere AI voice agent in your browser — 60 seconds, no signup.
from enum import Enum
from dataclasses import dataclass
from typing import Optional
class ErrorCategory(Enum):
LLM = "llm"
TOOL = "tool"
NETWORK = "network"
BUSINESS_LOGIC = "business_logic"
class ErrorSeverity(Enum):
RECOVERABLE = "recoverable"
DEGRADED = "degraded"
FATAL = "fatal"
@dataclass
class AgentError:
category: ErrorCategory
severity: ErrorSeverity
message: str
original_exception: Optional[Exception] = None
retry_eligible: bool = True
context: dict = None
def __post_init__(self):
if self.context is None:
self.context = {}
Tools are the hands of your agent. When a database query fails, an API returns unexpected data, or a file system operation is denied, the agent must distinguish between a tool that is temporarily down and one that received bad input.
class ToolErrorClassifier:
"""Classifies tool errors to determine the correct recovery strategy."""
TRANSIENT_EXCEPTIONS = (
ConnectionError,
TimeoutError,
OSError,
)
@staticmethod
def classify(tool_name: str, exc: Exception) -> AgentError:
if isinstance(exc, ToolErrorClassifier.TRANSIENT_EXCEPTIONS):
return AgentError(
category=ErrorCategory.TOOL,
severity=ErrorSeverity.RECOVERABLE,
message=f"Tool '{tool_name}' hit a transient error: {exc}",
original_exception=exc,
retry_eligible=True,
context={"tool": tool_name},
)
if isinstance(exc, ValueError):
return AgentError(
category=ErrorCategory.TOOL,
severity=ErrorSeverity.DEGRADED,
message=f"Tool '{tool_name}' received invalid input: {exc}",
original_exception=exc,
retry_eligible=False,
context={"tool": tool_name},
)
return AgentError(
category=ErrorCategory.TOOL,
severity=ErrorSeverity.FATAL,
message=f"Tool '{tool_name}' failed unexpectedly: {exc}",
original_exception=exc,
retry_eligible=False,
context={"tool": tool_name},
)
Network errors are the most common transient failure. They include DNS resolution failures, TLS handshake timeouts, connection resets, and HTTP 5xx responses from upstream providers.
These are the most dangerous because they look like success. The LLM returns valid JSON, the tool executes without exception, but the result violates a business rule — for example, booking an appointment in the past or transferring funds exceeding an account balance.
class BusinessRuleValidator:
"""Validates agent outputs against business rules before execution."""
def __init__(self):
self.rules = []
def add_rule(self, name: str, check_fn, error_msg: str):
self.rules.append({"name": name, "check": check_fn, "msg": error_msg})
def validate(self, action: dict) -> list[AgentError]:
errors = []
for rule in self.rules:
if not rule["check"](action):
errors.append(AgentError(
category=ErrorCategory.BUSINESS_LOGIC,
severity=ErrorSeverity.FATAL,
message=rule["msg"],
retry_eligible=False,
context={"action": action, "rule": rule["name"]},
))
return errors
# Usage
validator = BusinessRuleValidator()
validator.add_rule(
"future_date",
lambda a: a.get("date") and a["date"] > "2026-03-17",
"Cannot schedule appointments in the past.",
)
The key insight is routing every error through a single handler that decides the response based on category and severity.
Still reading? Stop comparing — try CallSphere live.
CallSphere ships complete AI voice agents per industry — 14 tools for healthcare, 10 agents for real estate, 4 specialists for salons. See how it actually handles a call before you book a demo.
class AgentErrorHandler:
def handle(self, error: AgentError) -> str:
if error.severity == ErrorSeverity.RECOVERABLE and error.retry_eligible:
return "retry"
elif error.severity == ErrorSeverity.DEGRADED:
return "fallback"
else:
return "abort"
This taxonomy becomes the foundation for every resilience pattern covered in the remaining posts of this series.
A blanket try/except hides the root cause and makes it impossible to choose the right recovery strategy. Retrying a business logic error wastes tokens and time, while aborting on a transient network glitch leaves money on the table. Categorization enables targeted responses.
Always before. Once a tool has executed a destructive action — sending an email, charging a card — you cannot undo it. Validate the planned action against business rules before calling the tool, and only allow execution if all checks pass.
Parse the LLM output with a strict schema validator such as Pydantic. If the model returns a tool call that does not match any registered tool name or produces arguments that fail validation, classify it as an LLM error with recoverable severity. Re-prompt the model with the validation error and let it self-correct, up to a maximum retry count.
#ErrorHandling #AIAgents #FailureModes #Python #Resilience #AgenticAI #LearnAI #AIEngineering

Written by
Sagar Shankaran· Founder, CallSphere
LinkedInSagar Shankaran is the founder of CallSphere, where he builds production AI voice and chat agents deployed across healthcare, hospitality, real estate, and home services. He writes about agentic AI, LLM engineering, and shipping voice agents that handle real calls in production.
See how AI voice agents work for your industry. Live demo available -- no signup required.
How resilient small businesses in Kyiv, Lviv and across Ukraine use CallSphere AI voice and chat agents to answer every call 24/7 in Ukrainian, Russian and English, book appointments and recover lost revenue.
A founder's guide to the personal AI assistant market: best AI assistant apps, business-grade options, and how CallSphere's voice agent fits in.
A founder's guide to free AI agents, low-code AI agent builders, and how to know when you should pay for a real platform like CallSphere.
Graphiti is the open-source temporal knowledge graph for AI agents in 2026. Learn how bi-temporal memory beats vector RAG for voice agents and long-running LLMs.
Chatbot app vs ChatGPT in 2026: a founder's clear take on the difference, when to use which, and how a real AI chatbot app development works.
How we built a fault-tolerant HVAC emergency triage and tech-dispatch platform on Kubernetes — three-tier CQRS, 11 micro-agents on the OpenAI Agents SDK + LangGraph, NATS JetStream, DTMF/SMS/WebSocket acceptance, circuit breakers, and an evaluation pipeline that catches regressions before they wake a tech at 3 AM.
© 2026 CallSphere Inc. All rights reserved.
Made within San Francisco
Watch how CallSphere handles real customer calls, schedules appointments, and processes payments — live.
Try Live DemoBook a DemoCalculate Your ROI