Bird
0
0

Which code snippet correctly implements a guardrail to block the 'delete_file' action in an AI agent?

easy📝 Syntax Q3 of 15
Agentic AI - Agent Safety and Guardrails
Which code snippet correctly implements a guardrail to block the 'delete_file' action in an AI agent?
A<pre>if action = 'delete_file': return 'Blocked'</pre>
B<pre>if action == 'delete_file': return 'Blocked'</pre>
C<pre>if action != 'delete_file': return 'Blocked'</pre>
D<pre>if action == 'delete_file': return 'Allowed'</pre>
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct comparison operator

    Use '==' to compare values, not '=' which is assignment.
  2. Step 2: Understand logic for blocking

    If the action is 'delete_file', it should be blocked.
  3. Step 3: Verify return value

    Return 'Blocked' when the action matches 'delete_file'.
  4. Final Answer:

    if action == 'delete_file': return 'Blocked' -> Option B
  5. Quick Check:

    Correct syntax and logic for blocking [OK]
Quick Trick: Use '==' for comparison and block matching actions [OK]
Common Mistakes:
  • Using '=' instead of '==' for comparison
  • Blocking actions that should be allowed
  • Returning 'Allowed' when blocking is needed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Agentic AI Quizzes