Course contentsShow
← AI Engineering
Lesson 577 of 1,88614. Function Calling and Tool UseFree lesson

Graceful Degradation Strategies

Handle function execution failures by providing fallback responses, retries, or alternative tool choices.

Graceful Degradation Strategies

You'll learn: How to keep your AI system running smoothly even when function calls fail, by implementing fallback responses, retry logic, and alternative tool selections.

Why Graceful Degradation Matters

When an LLM attempts to call a function, things can go wrong: the API might be down, arguments might be invalid despite validation, or execution might time out. Instead of crashing or leaving users hanging, your system should degrade gracefully—continue operating with reduced functionality rather than complete failure.

Think of it like a car's backup camera failing: the car doesn't stop working; you just use your mirrors instead.

Core Strategies

1. Fallback Responses

When a tool fails, provide a helpful message instead of silence:

try:
    result = execute_function(function_name, args)
except Exception as e:
    result = "I couldn't complete that action, but I can help explain the process manually."

2. Retry Logic

Temporary failures (network issues, rate limits) often resolve themselves:

for attempt in range(3):
    try:
        result = execute_function(function_name, args)
        break
    except TemporaryError:
        if attempt < 2:
            time.sleep(2 ** attempt)  # exponential backoff

3. Alternative Tool Selection

If one tool fails, try equivalent alternatives:

if "search_api" in available_tools and search_api_failed:
    # Fall back to simpler search method
    alternative_result = use_basic_search(query)

When to Apply Each Strategy

  • Fallback responses: When failure is unrecoverable and you need to inform the user
  • Retries: For transient network or rate limit errors
  • Alternative tools: When multiple tools can accomplish similar goals

Key Takeaway: Graceful degradation keeps your AI system responsive and user-friendly by planning for failure modes and implementing recovery strategies like fallbacks, retries, and tool alternatives.