Prompt injection and trust boundaries
Keep untrusted retrieved content from acquiring tool authority through an AI application's instruction channel.
On this page
The question for today
What you’ll understand
- Explain indirect prompt injection as an authority-boundary failure.
- Separate model behavior controls from independently enforced tool permissions.
- Calculate conditional residual risk without claiming a general injection defense.
An assistant reads a customer-provided document to summarize it. The document contains text that asks for an unrelated administrative action. The customer supplied information to analyze, not authority to control the application. Prompt injection becomes especially consequential when generated text can trigger tools, retrieve private context, or send information elsewhere. The central design question is which component has the final right to authorize those effects.
Distinguish content from authority
Direct injection arrives through an interaction controlled by the user; indirect injection arrives through a lower-trust source such as a retrieved passage, web page, or tool response. Original research demonstrates that an AI application can treat this supplied content as instructions. Describe the issue through source and authority rather than a list of forbidden phrases: benign documents may quote instructions, while malicious content can be phrased in many ways.
Annotate the provenance of each context item and keep trusted instructions distinct from quoted material where supported. Clear formatting, constrained tasks, and training can improve behavior but should not be described as complete isolation. A language model still processes the content. Do not put secrets in its context merely because an instruction tells it not to disclose them; reduce accessible information to the current task and caller's permissions.
Constrain effects outside the model
Use typed tool arguments, explicit allowlists where suitable, resource-scoped credentials, and destination checks. Validate on the server using an authenticated user identity, not a name asserted in model output. Separate read-only analysis from write actions and require an appropriate approval path for consequential changes. An approval must show the actual effect and remain bound to those parameters through execution, retries, and any asynchronous worker.
A retrieval service should enforce document access before returning passages. A sending service should independently enforce who may send which object to which destination. These separate gates reduce the chance that a single model error becomes an external effect. They do not settle every risk: an authorized user may still request a harmful action, and a plausible summary can mislead a reviewer. Keep semantic review, privacy rules, and operational authorization distinct.
Evaluate bounded claims
Build a defensive test suite spanning document formats, languages, multi-step tasks, retrieved metadata, and tool responses. Record success as a concrete security consequence, such as an unauthorized read or write, rather than whether the model repeats a suspicious phrase. Run tests in an isolated environment with synthetic private data and inert tool implementations. Include ordinary tasks to measure whether defenses make the assistant unusable.
Report the model version, prompts, tool schema, permission policy, test distribution, and uncertainty. A classifier that catches a known corpus is an additional signal, not a proof against adaptive inputs. Conditional evaluation can reveal whether a downstream authorization gate still works when the model is deliberately induced to propose an invalid action. That test supports a narrower and more useful claim than announcing that prompt injection has been solved.
Work it through
Measure an external authorization boundary
In a controlled synthetic suite, 200 of 1,000 cases produce disallowed tool proposals. The external gate blocks 198 of those 200. Calculate the proposal rate, conditional gate failure rate, and observed effect rate.
The disallowed-proposal rate is 200/1,000 = 20% for this test suite.
The conditional gate failure rate is (200 − 198)/200 = 1% among disallowed proposals.
The observed effect rate is 2/1,000 = 0.2%, also 20% × 1%.
Retain the two failing traces and repair their enforcement paths. The numbers describe this finite suite, not every possible document or adaptive attack.
Separate measurements show whether the language model and the authorization boundary fail in different ways, making remediation more precise.
The living notebook
Explore the model
Interactive lab · network
Inspect a score without granting authority
Adjust input x and weight w in the single sigmoid σ(wx − 0.5). It illustrates how a continuous score changes, not a prompt-injection detector, Transformer, attack simulator, or authorization service. No score value in this lab proves a document trustworthy.
- Product · wx
- 1.2
- Logit · wx − 0.5
- 0.7
- Sigmoid output
- 0.6682
One inspectable sigmoid unit, σ(wx − 0.5). Playback traces the computation graph. There is no training, attention mechanism or hidden deep network. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forA model score is evidence to interpret; an independently enforced policy decides whether an action may occur.
Pause & reason
Check your understanding
Your turn
Try it yourself
A synthetic suite has 500 cases. Fifty generate disallowed proposals and one passes the external gate. Compute both conditional gate failure and total observed effect rate. Explain why a content classifier cannot replace the gate.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Use fifty as the denominator for the conditional rate and five hundred for the total rate.
Compare with the solution
Conditional gate failure is 1/50 = 2%; total observed effect is 1/500 = 0.2%. A content classifier can miss unfamiliar or adaptive inputs and does not itself establish resource permissions. The external gate must continue checking concrete actions even when the classifier reports low risk.
Keep the idea
Take it with you
- Untrusted content must not acquire the application's authority through generated instructions.
- Structured output improves parsing while external permission checks constrain effects.
- Evaluate concrete consequences under explicit test conditions and retain failing traces.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.