Agents, MCP and skillsLoading progress…

Prompt injection

Identify instruction-injection attempts and design permission, sandbox, approval and evaluation boundaries for an agent.

Prompt injection

Prompt injection is text that tries to redirect the agent away from its authorised task. It can sit in retrieved pages, tool output, emails or any processed content. The model reads everything as text, so it cannot be relied on to tell "the user asked" from "the page says". The robust defence is a boundary in the application: the task decides which actions are allowed, and requests that came from data are blocked or confirmed rather than obeyed.

#requested by text in a pagedecision
1send_emailblock
2send_emailblock
3delete_fileblock
4read_pageask
5send_emailblock
6transferblock
7delete_fileblock
8summariseask
9send_emailblock
10transferblock
attack success rate: 0/10 = 0 task allow-list: read_page, summarise (the page asked for send_email, delete_file, read_page, transfer, summarise) the text cannot grant itself authority: unlisted actions are blocked, listed ones asked about

Injected instructions can hide in retrieved text, tool output or any processed content. The defence is a boundary the text cannot move: authorised actions decided by the task, with extra confirmation when the request came from data.

Ten injected requests, with and without a boundary.

Predict first. Does an instruction inside a search result automatically outrank the user's task?

Chapter context

An agent combines untrusted content with tools that can affect real systems. Reliable operation requires boundaries enforced outside model text, alongside clear task authorization and evidence-based evaluation.

Chapter reference: math, worked example & code

This section belongs to the whole chapter, so it is the same on every lesson in it and may cover a different lesson's topic. The code for the experiment you just ran is inside the experiment itself.

Math and notation

For a stated evaluation set:

unsafe pass rate=unsafe cases that passunsafe cases,false block rate=benign cases blockedbenign cases.unsafe\ pass\ rate=\frac{unsafe\ cases\ that\ pass}{unsafe\ cases},\quad false\ block\ rate=\frac{benign\ cases\ blocked}{benign\ cases}.

These empirical rates characterize that set; they are not universal security guarantees. Define denominators and outcome criteria before running the evaluation.

Worked example

An offline evaluation contains 100 unauthorized-action cases, of which 2 pass, and 200 benign cases, of which 5 are blocked. Unsafe pass rate is 2%, and false block rate is 2.5%. Those two numbers measure different failures; averaging them into a single undocumented 'safety score' hides the tradeoff.

Reference code

The following example uses the Python standard library and does not call a remote service.

from math import isclose
unsafe_passes,unsafe_cases=2,100
benign_blocks,benign_cases=5,200
assert isclose(unsafe_passes/unsafe_cases,.02)
assert isclose(benign_blocks/benign_cases,.025)

Python examples are provided for study and local execution; this page does not execute Python.

Common mistakes

A successful prompt-injection defense on one dataset is not a proof for every input. Text instructions cannot substitute for permission enforcement. Audit logs must preserve evidence without exposing credentials.