Course contentsShow
← AI Engineering
Lesson 185 of 1,8865. Advanced Prompting TechniquesFree lesson

Error Handling in Action-Oriented Prompts

Prompting strategies for recovering from failed actions and invalid tool calls.

Error Handling in Action-Oriented Prompts

What You'll Learn

You'll learn how to design prompts that gracefully recover when an LLM generates invalid tool calls or actions fail during execution.

The Core Problem

In action-oriented systems (like ReAct), the model generates actions to execute—searching databases, calling APIs, running calculations. But things go wrong: the model might hallucinate a non-existent tool, pass invalid parameters, or an action might fail due to external issues (API timeout, missing data). Without error handling, your agent simply breaks or loops endlessly.

Recovery Strategies

1. Error Feedback in Observations

When an action fails, include the error message in the next observation. The model can then reason about what went wrong and try a different approach.

Thought: I'll search for the user's order history.
Action: search_orders(user_id="invalid_format")
Observation: Error - user_id must be a number, not a string.
Thought: I need to convert the user_id first...

2. Explicit Error Instructions

In your system prompt, tell the model how to handle failures:

If a tool returns an error, analyze the error message and either:
- Retry with corrected parameters
- Choose a different tool
- Ask the user for clarification
Never repeat the exact same failed action.

3. Retry Limits and Fallback

In your orchestration code (outside the prompt), track failed attempts. After 3 consecutive errors on the same action type, you might force the model to acknowledge limitation or escalate to a human.

Analogy

Think of it like giving directions to someone with a phone that sometimes loses GPS signal. You don't just stop—you tell them "the signal failed, try using street signs instead" and give them alternative navigation strategies.

Key Takeaway: Error handling in action-oriented prompts requires feeding failure information back to the model with clear instructions on recovery strategies, combined with external guardrails to prevent infinite retry loops.