Slides · Safety and guardrails

Limiting blast radius and treating output as untrusted

Limiting blast radius and treating output as untrusted

Controls that still work when the model has been fooled: what it can reach, and what happens to what it writes.

Concept

When the detector misses

  • Detectors eventually miss. Then the damage is decided by what the agent was allowed to do.
  • A model that can only draft text produces a bad draft. One holding write access, a send tool and a database login produces an incident.
  • The reply is also not a finished answer: it is a string your code will render, query or run.
  • This lesson covers four OWASP 2025 entries: LLM02 Sensitive Information Disclosure, LLM05 Improper Output Handling, LLM06 Excessive Agency, LLM07 System Prompt Leakage.

Two things you will be able to do:

  1. Limit a hijacked agent with least privilege, authorization in code, approval and the trifecta test.
  2. Treat model output as untrusted input to the next system.

Source1 2025 Top 10 Risk & Mitigations for LLMs and Gen AI Apps

Concept

Two questions for any agent

  1. If the model were fully fooled right now, what is the worst it could do? Shrink that.
  2. What happens to its output next? Validate it before the next system trusts it.

Blast radius is what a hijacked agent can reach and do. The first question is about reach, the second is about what the model’s text is allowed to become.

Diagram

Same injection, different damage

Diagram: A successful injection against a broad agent can read everything, send anywhere and change data.

Narrow agent, fooled

Hijacked agent

Read one user's mail,
read-only

Draft a reply,
a human sends it

Broad agent, fooled

Hijacked agent

Read all mail

Send to anyone

Write and delete data

Diagram summary: A successful injection against a broad agent can read everything, send anywhere and change data. Against a narrow agent with scoped read-only tools and a human send step, the worst case is a misleading summary or a draft that gets rejected.

Compare

Three causes of excessive agency

Root causeMeaningExampleMatching control
Excessive functionalityTools the task does not needA document reader that can also deleteFewer tools, granular over open-ended ones
Excessive permissionsA tool has more downstream access than its job needsWrite rights where read is enoughMinimum permissions, such as read-only
Excessive autonomyHigh-impact actions run uncheckedSending money with no reviewHuman approval for high-impact actions

Source2 LLM06:2025 Excessive Agency

Concept

Authorization lives in code, not in the model

  • Check who is asking, and what they may do, in your executor against the real session.
  • Never take the user id or a permission level from the model’s arguments: a model can often be argued into another value, while an if statement cannot.
  • OWASP says to enforce authorization in the downstream system, not to ask the LLM whether an action is allowed, and to run actions as the specific user with minimum privileges, for example narrow OAuth scopes.
  • Rate limits and audit logs do not prevent an attack, but they cap how much damage fits in a minute and let you reconstruct it.

Sources2 LLM06:2025 Excessive Agency3 LLM Prompt Injection Prevention Cheat Sheet

Code

The executor decides, the model only proposes

A Python and SQLite sketch, run to confirm the outputs shown. Setup, not shown (also import contextlib, sqlite3): table orders(id, customer, status) with order 1 for c1 (shipped) and order 2 for c2 (packed); p is the database path.

Python

def lookup_order(session_customer, proposed_args):
    if type(proposed_args.get("order_id")) is not int:   # exact int only
        return "rejected"
    with contextlib.closing(read_only_db()) as db:   # defined on the next code slide
        row = db.execute(
            "select status from orders where id=? and customer=?",
            (proposed_args["order_id"], session_customer),   # identity from the session
        ).fetchone()
    return row[0] if row else "not found"

lookup_order("c1", {"order_id": 1, "customer": "c2"})  # 'shipped'
lookup_order("c1", {"order_id": 2})                    # 'not found'
lookup_order("c1", {"order_id": True})                 # 'rejected'
  • The customer the model passed is ignored; the session says the caller is c1.
  • Order 2 belongs to c2, so a fooled model asking for it gets nothing.
  • The check accepts only a real integer: int(True) and int(1.9) would both silently become 1, so conversion alone is not validation.

Source2 LLM06:2025 Excessive Agency

Process

Where a human belongs

Diagram: Routine actions run with limits and logs.

no

yes

yes

no

Proposed action

Irreversible, high-value
or external?

Run, with rate limit
and audit log

Show the exact action

Human approves?

Execute with scoped
credentials

Do not run, log it

Diagram summary: Routine actions run with limits and logs. Irreversible, high-value or external ones go to a person who sees the exact action rather than a model’s summary of it, and run only if approved. Putting approval only where it matters keeps reviewers attentive.

Sources2 LLM06:2025 Excessive Agency3 LLM Prompt Injection Prevention Cheat Sheet

Compare

The cost of approving everything

PolicyBenefitCost
No approvalFastA fooled model’s irreversible action runs at once
Approve only irreversible or external actionsReviewers see few, serious promptsYou must judge which actions qualify
Approve every callLooks safestSlow for honest users; reviewers may start clicking through without reading

Which actions deserve a human is a judgment about the cost of failure, not a fixed list. Approval complements code-level authorization; it does not replace it.

Diagram

The lethal trifecta

Diagram: Simon Willison (2025) names three capabilities that are dangerous together: private data, untrusted content and an outward channel.

Access to
private data

All three in
one agent

Exposure to
untrusted content

Ability to communicate
externally

Data-theft risk:
split the agent

Diagram summary: Simon Willison (2025) names three capabilities that are dangerous together: private data, untrusted content and an outward channel. Each is manageable alone. His advice is to avoid the combination entirely. Splitting a read-and-summarise step from a separate, approved send step is this course’s way of doing that.

Source4 The lethal trifecta for AI agents: private data, untrusted content, and external communication

Worked example

Worked: audit a refund agent’s tools

Hypothetical tool inventory. Marks: P = private data, U = reads untrusted content, E = can send outward.

Assumptions that make the marks true: lookups are scoped to the ticket’s own customer; the reply to the ticket author is plain text with no auto-loaded or model-written links; refunds go only to the original payment method.

ToolPUEDecision
read_ticket (customer text)yesyesnoKeep
lookup_orderyesnonoKeep, scoped read-only
issue_refundyesnonoKeep, cap and approval in code (E = no only because of the original-payment-method rule)
send_emailnonoyesRemove from this agent
fetch_urlnoyesyesRemove (open-ended)
  • Before: read_ticket supplies U, lookup_order supplies P and send_email supplies E, so one agent had all three.
  • After removing send_email and fetch_url, no tool gives E, provided the assumptions above hold. Willison also counts things like showing a link for a user to click as an outward channel, so a reply that contains model-written links would reopen the path.
  • If the business needs email, add a separate step where a human reviews the draft and sends it.

Sources4 The lethal trifecta for AI agents: private data, untrusted content, and external communication2 LLM06:2025 Excessive Agency

Check yourself

Check: which tool goes?

A travel assistant reads a user’s saved passport details, summarises web pages of hotel reviews, and has a book_and_pay tool (bookings go only to one fixed, vetted provider and carry no free-form text) plus a send_message tool that can message any phone number. Pick the single tool you would remove or gate first and say what it costs the product.

Answer

Gate or remove send_message to arbitrary numbers: it is the outward channel, and the other two legs (private passport data, untrusted review pages) are needed for the job. Cost: confirmations go through a fixed channel, or a human sends them. book_and_pay also deserves approval, since it is irreversible. It is not an open channel only because of the fixed provider and no free-form data; if it could send arbitrary text or details to arbitrary recipients, it would be a second outward leg.

Concept

Model output is attacker-influenced input

  • Prompts can steer output, so whatever the model writes may have been shaped by an attacker.
  • OWASP names this risk Improper Output Handling: model text reaching other components without enough checking or cleaning.
  • Its advice is a zero-trust stance: treat the model as you would an untrusted user, and check what it returns before backend code acts on it.
  • Where the output goes decides the risk, and the control.

Source5 LLM05:2025 Improper Output Handling

Compare

Destination decides the control

Output flows intoRiskControl
A web pageScript in generated HTML or Markdown (XSS)Encode for the destination, sanitise Markdown
A SQL querySQL injection or destructive statementsParameterise values; read-only database role
A shell, exec or evalRemote code executionDo not do it; if code must run, sandbox with no secrets, no network
A file pathPath traversalAllow-list of paths
An image or link URLData in the URLAllow-list domains

OWASP lists parameterised queries and context-aware encoding. The read-only role, sandbox and path allow-list are this course’s added advice. So is domain allow-listing, which closes the image route only when the allowed domains hold no user-controllable content and no open redirects; otherwise it only makes it harder.

Source5 LLM05:2025 Improper Output Handling

Code

Parameterising is not enough on its own

SQLite’s mode=ro is a connection flag, not a database role, and testing (Python 3.14, SQLite 3.50.4; behaviour can vary with the SQLite version) showed it is not enough: SQL that the model writes can ATTACH a database file in write mode, or turn off PRAGMA query_only. A SQLite authoriser that allows only reads closes those routes:

Python

import sqlite3

ALLOWED = {sqlite3.SQLITE_SELECT, sqlite3.SQLITE_READ, sqlite3.SQLITE_FUNCTION}

def read_only_db():
    db = sqlite3.connect(f"file:{p}?mode=ro", uri=True)
    db.set_authorizer(lambda action, *_: sqlite3.SQLITE_OK
                      if action in ALLOWED else sqlite3.SQLITE_DENY)
    return db     # the caller should close it (try/finally or contextlib.closing)

In that test run (same versions), each of these model-written statements failed with “not authorized”: delete from orders, drop table orders, attach database '<path>' as w, attach with mode=rw, attach of a new file path, and pragma query_only=OFF. No new file appeared.

  • The authoriser still allows almost every SELECT and SQL function (recursive CTEs and pragmas are denied), so a huge cross join can run for a long time. Add a time limit with set_progress_handler (a test interrupted a triple cross join at 0.5 s) or a row limit.
  • Parameterisation protects a fixed template when the model supplies only values. It does not stop a whole statement the model wrote.
  • In a server database the equivalent is a role granted only SELECT. A read-only role stops writes, not over-broad reads: select count(*) from orders still counted every customer’s rows, so scope reads per user as well.
  • Encoding fits the destination: html.escape('<img src="https://evil.example/?q=secret">') returns inert text for a page, and is no use for SQL.

Source5 LLM05:2025 Improper Output Handling

Check yourself

Check: spot the weakest destination

A report tool asks a model for a file name, builds /exports/<name>.csv from it, then renders the model’s chat reply as raw Markdown that auto-loads images. Which two output flows need a control, and which?

Answer

The file path needs validation against an allow-list (path traversal could escape /exports). The rendered Markdown needs sanitising and an allow-list of image domains, since an auto-loaded image URL can carry data out. Both treat model text as untrusted before the next system uses it.

Diagram

Data the model never sees cannot leak

Diagram: Minimise the fields, swap identifiers for tokens before the call, filter the output for sensitive patterns, then restore real values only...

Customer record

Send only needed fields

Replace identifiers
with tokens

Model call

Filter output for
card and id patterns

Re-insert real values
only where needed

Diagram summary: Minimise the fields, swap identifiers for tokens before the call, filter the output for sensitive patterns, then restore real values only where the reply needs them. OWASP lists least-privilege access, tokenisation and redaction among its controls. Pattern filters miss variants, and provider retention terms differ, so check them for your plan.

Source6 LLM02:2025 Sensitive Information Disclosure

Concept

Assume the system prompt can leak

  • OWASP says sensitive data does not belong in prompt text and that the prompt should not be considered a secret.
  • It also says a prompt should not be used as a security control: authorization and privilege separation must not be delegated to the model.
  • So keys, credentials and access rules live in server-side code and credentials.
  • A prompt line that forbids revealing data helps, but can be bypassed, so it is never the only control.

Sources7 LLM07:2025 System Prompt Leakage6 LLM02:2025 Sensitive Information Disclosure

Summary

Summary

  • Blast radius is what a hijacked agent can reach. Shrink it with least privilege, authorization in code and approval.
  • Excessive agency has three causes: too many tools, too much permission, too much autonomy.
  • Avoid private data, untrusted content and an outbound channel together in one agent.
  • Approve irreversible and external actions, not every action.
  • Model output is untrusted input: validate against a schema, encode for the destination, use a read-only database role, sandbox code, allow-list URLs.
  • Keep secrets and authorization logic in code, not in the system prompt.

References

References & Sources (1 of 2)

  1. 2025 Top 10 Risk & Mitigations for LLMs and Gen AI Apps (opens in a new tab)

    OWASP GenAI Security Project2025Documentation

    Used for The four 2025 list entries this lesson covers by name and number.

  2. LLM06:2025 Excessive Agency (opens in a new tab)

    OWASP GenAI Security Project2025Documentation

    Used for Three root causes (excessive functionality, permissions, autonomy), minimum-permission and per-user execution, human approval for high-impact actions, authorization in downstream systems, and the email-assistant scenario.

  3. LLM Prompt Injection Prevention Cheat Sheet (opens in a new tab)

    OWASP Cheat Sheet Series2026Documentation

    Used for Enforce permissions in code outside the model, approval checked against the exact action, and treating model output as untrusted at every downstream use.

  4. The lethal trifecta for AI agents: private data, untrusted content, and external communication (opens in a new tab)

    Simon Willison2025Article

    Used for The lethal trifecta of private data, untrusted content and external communication, and the advice to avoid combining all three.

  5. LLM05:2025 Improper Output Handling (opens in a new tab)

    OWASP GenAI Security Project2025Documentation

    Used for Improper output handling as insufficient validation of model output before downstream use; consequences, vulnerability examples and prevention (context-aware encoding, parameterised queries, treating the model as an untrusted user).

References

References & Sources (2 of 2)

  1. LLM02:2025 Sensitive Information Disclosure (opens in a new tab)

    OWASP GenAI Security Project2025Documentation

    Used for Least-privilege access to sensitive data, tokenisation and pattern-based redaction, and the warning that prompt instructions about data can be bypassed.

  2. LLM07:2025 System Prompt Leakage (opens in a new tab)

    OWASP GenAI Security Project2025Documentation

    Used for The system prompt should not be treated as secret or as a security control; authorization belongs outside the model.