Building approval gates

Step 1: classify your tools as sensitive or safe. Safe tools auto-execute. Sensitive tools pause and wait for human approval.

Always the developer. This is a hardcoded classification, not something the LLM decides at runtime. You know your system best. Tools that modify data, send communications, or control physical devices should be marked sensitive. The LLM should never be able to bypass these gates.

08-human-in-the-loop.ipynb
python
# Classify tools by sensitivity
SENSITIVE_TOOLS = {"unlock_front_door", "send_email"}
SAFE_TOOLS = {"get_weather", "check_calendar"}

A simple set-based classification. Sensitive tools require human approval.

With tools classified, we can build the approval gate. When the agent wants to call a sensitive tool, it pauses and asks the human for confirmation before executing.

08-human-in-the-loop.ipynb
python
def run_security_agent(query: str):
    prompt = (
        "You are a security assistant. "
        "If the user wants to open the door, "
        "respond with [ACTION: UNLOCK]."
    )
    response = ask_llm(prompt, query)

    if "[ACTION: UNLOCK]" in response:
        print("CRITICAL ACTION: Unlock Front Door")

        # THE HUMAN GATEWAY
        approval = input(
            "Do you approve? (yes/no): "
        ).strip().lower()

        if approval == "yes":
            return unlock_front_door()
        else:
            return "Action denied by human."

    return f"Agent Response: {response}"

The approval gate: when a sensitive action is detected, pause and ask the human before executing.

Approval gate decision flow

08-human-in-the-loop.ipynb
python
# Full security-first agent with HITL
def execute_with_approval(tool_name, tool_args,
                          available_functions):
    if tool_name in SENSITIVE_TOOLS:
        print(f"\nSECURITY CHECK: {tool_name}")
        print(f"Arguments: {tool_args}")
        approval = input(
            "Approve? (yes/no): "
        ).strip().lower()

        if approval != "yes":
            return "Error: Action denied by human."

    return available_functions[tool_name](**tool_args)

A reusable approval wrapper. Checks sensitivity, prompts for approval, and either executes or denies.

Fill in the blanks: Add an approval gate to a tool

Loading practice…

Matching exercise: Classify tools as sensitive or safe

Loading practice…