Bird
Raised Fist0
Agentic AIml~10 mins

Output filtering and safety checks 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 add a simple output filter that blocks offensive words.

Agentic AI
def filter_output(text):
    blocked_words = ['badword1', 'badword2']
    for word in blocked_words:
        if word in text:
            return [1]
    return text
Drag options to blanks, or click blank then click option'
A""
B"[Content blocked]"
Ctext
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Returning the original text even when blocked words are found.
Returning None which might cause errors downstream.
2fill in blank
medium

Complete the code to check if the model output length exceeds the safety limit.

Agentic AI
def check_length(output):
    max_length = 100
    if len(output) [1] max_length:
        return False
    return True
Drag options to blanks, or click blank then click option'
A!=
B<
C==
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' which would block short outputs instead.
Using '==' which only blocks outputs exactly equal to max_length.
3fill in blank
hard

Fix the error in the code that filters outputs containing sensitive keywords.

Agentic AI
def safe_output(text):
    sensitive_keywords = ['password', 'secret']
    if any([1] in text for [2] in sensitive_keywords):
        return '[Filtered]'
    return text
Drag options to blanks, or click blank then click option'
Ak, keyword
Bkeyword, k
Ckeyword, keyword
Dk, k
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the variable names causing syntax errors.
Using the same variable name twice causing confusion.
4fill in blank
hard

Fill both blanks to create a dictionary filtering outputs by length and keyword presence.

Agentic AI
outputs = ['safe text', 'too long text example', 'contains secret']
filtered = {text: len(text) for text in outputs if len(text) [1] 15 and 'secret' not in text [2]
Drag options to blanks, or click blank then click option'
A<
B>
Cand
Dor
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' which would filter out short texts.
Using 'or' which would allow texts with 'secret'.
5fill in blank
hard

Fill all three blanks to implement a safety check that blocks outputs with banned words or too long length.

Agentic AI
def safety_check(output):
    banned_words = ['hack', 'attack']
    max_len = 50
    if any([1] in output for [2] in banned_words) or len(output) [3] max_len:
        return False
    return True
Drag options to blanks, or click blank then click option'
Aword
Bw
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' for length which would block short outputs.
Using inconsistent variable names in the comprehension.