Read first
Task 16
Guardrails
A guardrail is a cheap check that runs before the model is asked anything. If the question is outside the academy, the bot refuses politely instead of guessing.
Task
When should a guardrail run?
The editor already contains a starting point. Change it until every check passes — the Next task button unlocks when it does.
What you start with
allowed = ['fee', 'fees', 'timing', 'admission', 'course', 'python', 'ai']
def on_topic(question):
words = question.lower().split()
return any(w in allowed for w in words)
print(on_topic('What is the Python fee?'))
print(on_topic('Write my history assignment'))
Python
1 automatic check Prompt engineering
Code editor
Ctrl + Enter runs
Run your code to see the output and the checks.
Your result
Submit your code to see results
Write your code in the middle column and press Run code.
Next task (pass every check first)
Hint
Ask yourself: When should a guardrail run?