BasicsSecurityLeast PrivilegeOpenAIAnthropicGoogle
Problem
Implement filter_allowed_tools(requested_tools, allowed_tools) that partitions requested_tools into (approved, blocked) lists, preserving the original order of requested_tools.
Why It Matters: Least-privilege tool allowlists stop prompt-injected agents from invoking destructive or unauthorized tools (like delete_db or send_wire_transfer).
Function Signature
def filter_allowed_tools(requested_tools: list[str], allowed_tools: list[str]) -> tuple[list[str], list[str]]:
"""Partition requested_tools into (approved, blocked) preserving order."""
Sample Input & Output
Example 1: Mixed Approved & Blocked Tools
Input:
requested_tools = ["search", "delete_db", "calc"], allowed_tools = ["search", "calc"]
Expected Output:
(["search", "calc"], ["delete_db"])
Explanation: 'search' and 'calc' are approved in order; 'delete_db' is routed to blocked.
Example 2: All Blocked / Empty Allowlist
Input:
requested_tools = ["shell_exec", "email"], allowed_tools = []
Expected Output:
([], ["shell_exec", "email"])
Explanation: An empty allowlist blocks every requested tool safely.
Constraints & Edge Cases
- Preserve original order in both returned lists.
- Convert
allowed_toolsto asetfor O(1) membership checks. - Preserve order and duplicates from
requested_tools.
Constraints & Evaluation Criteria
- Preserve original order in both returned lists.
Hints
Learn the Concept First
Python 3⌘/Ctrl+Enter to Run · ⌘/Ctrl+Shift+Enter to Submit
Loading Code Editor...
+1 Hidden Submit Case
Input / Scenario
['search','delete_db','calc']
Expected Output / Criteria
(['search','calc'], ['delete_db'])