0
0
Agentic AIml~10 mins

Error handling in tool calls in Agentic AI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to catch errors when calling a tool.

Agentic AI
try:
    result = tool.call(input_data)
except [1]:
    result = None
Drag options to blanks, or click blank then click option'
AException
BValueError
CKeyError
DTypeError
Attempts:
3 left
💡 Hint
Common Mistakes
Using a specific error like ValueError misses other error types.
Not catching any error causes the program to crash.
2fill in blank
medium

Complete the code to log the error message when a tool call fails.

Agentic AI
try:
    output = tool.call(data)
except Exception as [1]:
    logger.error(str([1]))
Drag options to blanks, or click blank then click option'
Aerror
Be
Cex
Derr
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name not matching the except clause causes a NameError.
Not converting the exception to string before logging.
3fill in blank
hard

Fix the error in the code to retry the tool call once after failure.

Agentic AI
try:
    result = tool.call(input)
except Exception:
    [1]  # retry once
    result = tool.call(input)
Drag options to blanks, or click blank then click option'
Aretry
Bcontinue
Cpass
Dbreak
Attempts:
3 left
💡 Hint
Common Mistakes
Using continue or break outside loops causes syntax errors.
Using a non-existent keyword like retry causes errors.
4fill in blank
hard

Fill both blanks to handle specific tool errors and log them.

Agentic AI
try:
    output = tool.call(data)
except [1] as e:
    logger.error(f"Tool error: {e}")
except [2] as e:
    logger.error(f"Timeout error: {e}")
Drag options to blanks, or click blank then click option'
AToolError
BTimeoutError
CValueError
DKeyError
Attempts:
3 left
💡 Hint
Common Mistakes
Using generic errors like ValueError misses specific tool errors.
Swapping the error types causes wrong error handling.
5fill in blank
hard

Fill all three blanks to safely call a tool with retries and error logging.

Agentic AI
for attempt in range([1]):
    try:
        result = tool.call(input_data)
        break
    except [2] as e:
        logger.warning(f"Attempt {attempt+1} failed: {e}")
else:
    logger.error("All attempts failed.")
    result = [3]
Drag options to blanks, or click blank then click option'
A3
BException
CNone
DValueError
Attempts:
3 left
💡 Hint
Common Mistakes
Using too few or too many retries.
Catching only specific errors and missing others.
Not setting a fallback result after failures.