deliver · advanced · 50 min

One door for every tool, with rules

Put every tool call through one checkpoint that decides allow, deny or ask a person, from rules kept in a file.

HANDS-ON LAB · YOU RUN IT ON YOUR MACHINE · 4 STEPS
  1. Step 1 of 4

    Route every tool call through one function that knows who is calling, which tool and with what

    Run this to check

    uv run pytest tests/test_gateway.py -q

    You pass when

    A test passes showing that no tool can be reached without going through the gateway.

    Files you write

    • gateway.py
    • tests/test_gateway.py
  2. Step 2 of 4

    Write three rules: support staff cannot pay, refunds over 100 need a person, everyone can look up a parcel

    Rules in a file can be read and signed off by someone who does not read code. Larger teams use a policy language such as Cedar for the same job.

    Run this to check

    uv run pytest tests/test_policy.py -q

    You pass when

    Tests pass for one allow, one deny and one needs-approval case.

    Files you write

    • policy.yaml
    • tests/test_policy.py
  3. Step 3 of 4

    Call a tool that no rule mentions

    Run this to check

    uv run pytest tests/test_policy.py -q -k unknown

    You pass when

    It is denied. Anything not allowed by a rule is refused.

    Files you write

    • tests/test_policy.py
  4. Step 4 of 4

    Record every decision with its reason

    Run this to check

    tail -n 3 audit.jsonl

    You pass when

    One line per call: who, tool, decision and the rule that decided it.

    Files you write

    • audit.jsonl
No transcript here on purpose. This page does not show terminal output, because model answers differ from run to run. Each step says what a pass looks like; your own terminal is the proof.