0
0
Prompt Engineering / GenAIml~20 mins

Fallback and error handling in Prompt Engineering / GenAI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Fallback Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why use fallback mechanisms in AI systems?

Imagine you have an AI chatbot that sometimes fails to understand user questions. Why is it important to have a fallback mechanism?

ATo provide a default response or alternative action when the AI cannot answer correctly
BTo make the AI ignore user inputs it does not understand
CTo stop the AI from responding to any question after one failure
DTo increase the AI's training data automatically without human help
Attempts:
2 left
💡 Hint

Think about what happens when the AI does not know an answer. What should it do instead of failing silently?

Predict Output
intermediate
2:00remaining
Output of fallback function in AI response

What is the output of the following Python code simulating a fallback in AI response?

Prompt Engineering / GenAI
def ai_response(user_input):
    responses = {'hello': 'Hi there!', 'bye': 'Goodbye!'}
    return responses.get(user_input, 'Sorry, I did not understand that.')

print(ai_response('hello'))
print(ai_response('thanks'))
AHi there!\nNone
BSorry, I did not understand that.\nSorry, I did not understand that.
CHi there!\nSorry, I did not understand that.
DNone\nNone
Attempts:
2 left
💡 Hint

Look at how the get method works with a default value.

Model Choice
advanced
2:00remaining
Choosing a model with built-in error handling

You want to deploy an AI model that can gracefully handle uncertain inputs by providing fallback answers. Which model type is best suited for this?

AA model trained only on a small fixed dataset without validation
BA deterministic rule-based model without uncertainty estimation
CA model that always outputs the most frequent answer regardless of input
DA probabilistic model that outputs confidence scores with fallback thresholds
Attempts:
2 left
💡 Hint

Think about how the model can know when it is unsure.

Hyperparameter
advanced
2:00remaining
Setting fallback threshold in AI confidence scores

In an AI system using confidence scores to decide when to fallback, which hyperparameter setting best balances accuracy and fallback frequency?

ASet a moderate confidence threshold to fallback only when confidence is low but not too often
BDisable confidence threshold and never fallback
CSet a very high confidence threshold so fallback triggers often, annoying users
DSet a very low confidence threshold so fallback triggers rarely, risking wrong answers
Attempts:
2 left
💡 Hint

Think about avoiding too many wrong answers and too many fallback messages.

🔧 Debug
expert
2:00remaining
Identify error in fallback implementation code

What is the output of the following Python code?

Prompt Engineering / GenAI
def fallback_response(input_text):
    try:
        result = 10 / int(input_text)
    except ValueError:
        return 'Input is not a number.'
    except ZeroDivisionError:
        return 'Cannot divide by zero.'
    return f'Result is {result}'

print(fallback_response('0'))
AOutputs: 'Input is not a number.'
BOutputs: 'Cannot divide by zero.'
CRaises TypeError
DOutputs: 'Result is 0'
Attempts:
2 left
💡 Hint

What happens when dividing by zero in Python?