AI Computer Science Academy · Faisalabad

AI & Prompt Engineering

Guardrails

Task 16 of 56 Python Prompt engineering
All tasks
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.

Checks on this task:

  • Check 1

Track progress

0 of 56 tasks complete

Next task unlocks when every check passes.

Sign in to keep your code and certificates.

Next task (pass every check first)