Bird
0
0

This AI agent code is meant to block unsafe commands but has a bug:

medium📝 Debug Q14 of 15
Agentic AI - Agent Safety and Guardrails
This AI agent code is meant to block unsafe commands but has a bug:
def guardrail(action):
    if action = 'shutdown':
        return 'Blocked'
    else:
        return 'Allowed'

What is the error and how to fix it?
AUse '==' instead of '=' in the if condition.
BChange 'return' to 'print' inside the function.
CRemove the else block entirely.
DAdd a colon ':' after the function name.
Step-by-Step Solution
Solution:
  1. Step 1: Identify the syntax error in the if statement

    The code uses '=' which is assignment, but it should compare with '==' in conditions.
  2. Step 2: Correct the if condition to use '=='

    Replace '=' with '==' to properly check if action equals 'shutdown'.
  3. Final Answer:

    Use '==' instead of '=' in the if condition. -> Option A
  4. Quick Check:

    Comparison needs '==' [OK]
Quick Trick: Use '==' for comparison, '=' is assignment [OK]
Common Mistakes:
  • Confusing assignment '=' with comparison '=='
  • Changing return to print unnecessarily
  • Removing else block without reason

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Agentic AI Quizzes