0
0
Agentic AIml~20 mins

Error handling in tool calls in Agentic AI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Error Handling Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of error handling in a tool call
What is the output of this code snippet that calls a tool and handles errors?
Agentic AI
def call_tool(tool, input_data):
    try:
        result = tool(input_data)
        return f"Success: {result}"
    except ValueError:
        return "ValueError caught"
    except Exception:
        return "General error caught"

def sample_tool(x):
    if x < 0:
        raise ValueError("Negative input")
    elif x == 0:
        raise RuntimeError("Zero input")
    else:
        return x * 2

output = call_tool(sample_tool, 0)
print(output)
ASuccess: 0
BValueError caught
CGeneral error caught
DRuntimeError: Zero input
Attempts:
2 left
💡 Hint
Think about which exception is raised and which except block catches it.
Model Choice
intermediate
2:00remaining
Choosing the right error handling model for tool calls
Which error handling model is best suited for a tool call that may raise multiple specific exceptions and needs to log errors distinctly?
AMultiple try-except blocks each catching one specific exception type separately
BSingle try-except block catching all exceptions with a general except clause
CTry-except with nested try blocks inside except clauses
DNo try-except, just let exceptions propagate to the caller
Attempts:
2 left
💡 Hint
Consider clarity and specific error handling needs.
🔧 Debug
advanced
2:00remaining
Identify the error in this tool call error handling code
What error will this code raise when calling the tool with input 5?
Agentic AI
def tool(x):
    if x == 5:
        raise KeyError("Key missing")
    return x

def call_tool(tool_func, val):
    try:
        return tool_func(val)
    except ValueError:
        return "Value error handled"
    except KeyError:
        return "Key error handled"
    except:
        return "Other error"

result = call_tool(tool, 5)
print(result)
ARaises an uncaught exception
BKey error handled
COther error
DValue error handled
Attempts:
2 left
💡 Hint
Check which except block matches the raised exception.
Hyperparameter
advanced
2:00remaining
Choosing retry count for error handling in tool calls
If a tool call fails due to a transient network error, which retry count is most reasonable to balance responsiveness and robustness?
A1 retry
B0 retries (fail immediately)
C10 retries
D100 retries
Attempts:
2 left
💡 Hint
Too many retries can cause delays; too few may miss recovery.
🧠 Conceptual
expert
3:00remaining
Best practice for error handling in asynchronous tool calls
Which approach best ensures error handling in asynchronous tool calls to avoid silent failures?
AUse callbacks without error handling
BIgnore errors and rely on the caller to handle exceptions
CWrap async calls in a synchronous try-except block
DUse try-except inside the async function and log errors before returning
Attempts:
2 left
💡 Hint
Think about where errors can be caught in async code.