Skip to content

Lesson 1 of 7 · 3 min read

Guardrails in Layers

Free lessonReviewed By the AIAgentInterviews editorial team
Reading position
In this lesson

TL;DR: Ask of every guardrail: does it still hold if the model is wrong or has been steered by something it read? Instructions in the prompt do not; code at the boundaries does. Layer the controls: label untrusted content, expose only the tools a task needs, validate and authorize every call in code, check what leaves the system, require people for consequential actions, and monitor afterwards. Then apply a structural rule: an agent that reads untrusted content and can reach sensitive data should not also be able to act or communicate externally without a person in between.

After this lesson, you should be able to distinguish behavioural guidance from enforceable controls, place controls at the right layer, explain what each layer catches and misses, and apply a structural rule for combining untrusted input, sensitive data and external action.

Before you read

Commit to an answer now. The lesson that follows explains it, and having guessed first, even wrongly, makes the explanation easier to remember.

  1. 1A team's only guardrail is a system-prompt line: 'Never send customer data outside the company.' Why is that not enough, and where would you add a control that holds?

The layers

WHERE CONTROLS HOLD
Guardrails from input to audit
  1. 1

    1 · Input handling

    label untrusted content

    • Mark retrieved and tool content as data
    • Track provenance through the run

    Misses: the model may still follow it

  2. 2

    2 · Tool exposure

    per task

    • Only the tools this task needs
    • Dangerous tools absent, not just discouraged

    Misses: misuse of the tools that remain

  3. 3

    3 · Tool boundary

    validate and authorize in code

    • Identity from the session
    • Limits, ownership, policy per call

    Misses: allowed actions with bad intent behind them

  4. 4

    4 · Output and egress

    what leaves

    • Check replies, links and arguments for sensitive data
    • Allowlist destinations

    Misses: data hidden in innocent-looking channels

  5. 5

    5 · Approval

    for consequential actions

    • Bound to the exact action
    • Shows evidence, not just a request

    Misses: rubber-stamping

  6. 6

    6 · Monitoring and audit

    after the fact

    • Anomalies, denials, unusual flows
    • Every decision recorded

    Catches what got through, late

Each layer is incomplete on its own; together, one failure is not enough for harm.

Guidance is not a control

System prompts, model training and classifiers that judge the model's intent all improve behaviour, and all can fail on unusual input. They belong in the design as ways to make bad proposals rarer. The controls that hold are the ones in code at boundaries the model cannot cross: what it can see, what it can call, what an action may do, what may leave.

A structural rule

Some combinations are dangerous whatever the prompt says. Simon Willison named one in 2025 as the combination of private data, untrusted content and the ability to communicate externally; Meta's "Agents Rule of Two" (2025) proposed that an agent should have at most two of: processing untrusted input, access to sensitive systems or data, and the ability to change state or communicate externally, unless a person approves. The harness can enforce it per run:

def gate(run, tool):
    untrusted = run["read_untrusted"]
    sensitive = run["touched_sensitive"]
    acts_out = tool["external"] or tool["writes"]
    if untrusted and sensitive and acts_out:
        return "needs_approval"
    return "allow"

send = {"name": "email_send", "external": True, "writes": True}
lookup = {"name": "orders_get", "external": False, "writes": False}
run = {"read_untrusted": True, "touched_sensitive": True}       # read an inbound email
print(gate(run, lookup), gate(run, send))  # => allow needs_approval

The run that read an untrusted email and customer records can still look things up, but sending anything out needs a person. Without the untrusted read, the same send might proceed under normal policy.

Say it in 30 seconds

"A guardrail is a control that holds when the model is wrong or misled, so prompts are guidance, not guardrails. I layer controls: label untrusted content, expose only the tools a task needs, validate and authorize each call in code with identity from the session, check what leaves the system, require approval bound to exact actions for consequential steps, and monitor and audit. Structurally, a run that has read untrusted content and touched sensitive data needs a person before it acts or communicates externally."

Check yourself

Answer aloud or on paper before revealing. Producing the explanation unaided is exactly what a panel listens for.

  1. 1Why is removing a tool from a task stronger than instructing the model not to use it?

  2. 2What three capabilities does the 'rule of two' say an agent should not combine without a person?

  3. 3What does monitoring add if all the earlier layers are in place?

Practise it as an interviewer asks it

Course lessons that teach this

Related lessons