What problem does it solve?
Patterns for ensuring system resilience by detecting failures (API errors, hallucinations, validation errors) and executing predefined fallback logic. Use when user asks to "handle agent errors", "add error recovery", "make my agent fault-tolerant", or mentions exception handling, graceful degradation, or retry logic.
Core Features & Use Cases
Exception Handling ensures that an agentic system degrades gracefully rather than crashing. In the nondeterministic world of LLMs, failures are common: models hallucinate, APIs time out, and outputs are malformed. This pattern wraps critical operations in "try/catch" blocks that trigger recovery agents or fallback strategies.
Use Cases
- API Fallback: Primary model API failed? Switch to backup model API.
- Refusal Handling: If the model refuses to answer (due to safety filters), catch the refusal and rephrase or explain why it can't answer.
- Validation Repair: If JSON validation fails, pass the error back to the model to fix the syntax.
Quick Start
Wrap critical operations in try/catch blocks and implement predefined fallback strategies for API errors, timeouts, and validation issues.