0
0
Agentic AIml~10 mins

Handling retrieval failures gracefully 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 retrieval errors and return None.

Agentic AI
try:
    result = retrieve_data(query)
except [1]:
    result = None
Drag options to blanks, or click blank then click option'
ATypeError
BException
CKeyError
DValueError
Attempts:
3 left
💡 Hint
Common Mistakes
Catching only specific errors like KeyError may miss other failures.
Not catching any error causes the program to crash on failure.
2fill in blank
medium

Complete the code to retry retrieval up to 3 times on failure.

Agentic AI
for attempt in range(3):
    try:
        data = retrieve_data(query)
        break
    except [1]:
        continue
Drag options to blanks, or click blank then click option'
AException
BTimeoutError
CIndexError
DAttributeError
Attempts:
3 left
💡 Hint
Common Mistakes
Using a narrow exception may miss some errors and stop retries.
Not using try-except inside the loop causes crashes.
3fill in blank
hard

Fix the error in the retrieval fallback code to handle missing keys.

Agentic AI
try:
    value = data['key']
except [1]:
    value = default_value
Drag options to blanks, or click blank then click option'
AValueError
BTypeError
CKeyError
DIndexError
Attempts:
3 left
💡 Hint
Common Mistakes
Catching the wrong error type causes the fallback to fail.
Not catching any error leads to program crash on missing keys.
4fill in blank
hard

Fill both blanks to log retrieval failure and return fallback data.

Agentic AI
try:
    result = retrieve_data(query)
except [1] as e:
    logger.[2](f"Retrieval failed: {e}")
    result = fallback_data
Drag options to blanks, or click blank then click option'
AException
Berror
Dwarning
Attempts:
3 left
💡 Hint
Common Mistakes
Using a narrow exception misses some errors.
Logging with wrong method name causes runtime errors.
5fill in blank
hard

Fill all three blanks to implement a safe retrieval with retry and fallback.

Agentic AI
for attempt in range(3):
    try:
        data = retrieve_data(query)
        break
    except [1]:
        logger.[2](f"Attempt {attempt + 1} failed.")
else:
    data = [3]
Drag options to blanks, or click blank then click option'
AException
Bwarning
Cfallback_data
Derror
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong exception type causes missed retries.
Logging with wrong method name causes errors.
Not providing fallback data leads to undefined variables.