Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning the original text even when blocked words are found.
Returning None which might cause errors downstream.
✗ Incorrect
The function returns a placeholder string when blocked words are found to prevent offensive output.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' which would block short outputs instead.
Using '==' which only blocks outputs exactly equal to max_length.
✗ Incorrect
The function returns False if the output length is greater than the max allowed length.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the variable names causing syntax errors.
Using the same variable name twice causing confusion.
✗ Incorrect
The correct syntax is to check if 'k' (each keyword) is in text, iterating over 'keyword' in sensitive_keywords.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' which would filter out short texts.
Using 'or' which would allow texts with 'secret'.
✗ Incorrect
We want texts shorter than 15 and that do not contain 'secret', so use '<' and 'and'.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' for length which would block short outputs.
Using inconsistent variable names in the comprehension.
✗ Incorrect
We check if any banned word is in output using 'word' and 'w' as variables, and block if length is greater than max_len.
