Bird
Raised Fist0
Agentic AIml~10 mins

Why guardrails prevent agent disasters in Agentic AI - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a guardrail that stops the agent if it tries to delete important files.

Agentic AI
if action == [1]:
    print("Guardrail activated: Action blocked.")
Drag options to blanks, or click blank then click option'
A"delete_important_files"
B"move_files"
C"read_files"
D"create_files"
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing an action that is safe instead of dangerous.
2fill in blank
medium

Complete the code to check if the agent's output contains forbidden words.

Agentic AI
for word in forbidden_words:
    if word in agent_output:
        raise [1]("Forbidden content detected")
Drag options to blanks, or click blank then click option'
AValueError
BException
CWarning
DRuntimeError
Attempts:
3 left
💡 Hint
Common Mistakes
Using Warning which does not stop execution.
3fill in blank
hard

Fix the error in the guardrail function that prevents the agent from sending sensitive data.

Agentic AI
def guardrail_check(data):
    if 'password' [1] data:
        return False
    return True
Drag options to blanks, or click blank then click option'
Anot in
Bin
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' which checks equality, not membership.
4fill in blank
hard

Fill both blanks to create a guardrail that logs and blocks unsafe commands.

Agentic AI
def check_command(cmd):
    if cmd [1] unsafe_commands:
        log_event([2])
        return False
    return True
Drag options to blanks, or click blank then click option'
Ain
Bnot in
C"Blocked unsafe command"
D"Allowed command"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'not in' which allows unsafe commands.
5fill in blank
hard

Fill all three blanks to build a guardrail that filters outputs and raises an error if needed.

Agentic AI
def filter_output(output):
    filtered = [word for word in output.split() if word != [1]]
    if [2] in filtered:
        raise [3]("Disallowed word found")
    return ' '.join(filtered)
Drag options to blanks, or click blank then click option'
A"secret"
B"error"
CRuntimeError
D"allowed"
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong words or error types that don't stop execution.