Indirect Prompt Injection › Worked example
Language AI HandbookAll chapters Consider the benign visitor guide. It has an instruction-like mark and the reader has access to it. The reject strategy drops it. The restricted and minimum strategies retain the room so a question about location can still be answered from the guide. When the next view decision receives a permission set without that guide, all strategies deny it before building the view. The replay governs which already-loaded field values can be used for the answer.
PythonIn [12]Expand
withdrawn = all_visible - {example_row.source_id}
before = [
evaluate_row(example_row, all_visible, strategy) for strategy in Strategy
]
after = [
evaluate_row(example_row, withdrawn, strategy) for strategy in Strategy
]
for strategy, enabled, removed in zip(Strategy, before, after):
print(f"{strategy.value:16} {enabled[0].value:12} → {removed[0].value}")ConsoleOut [12]Expand
Reject marked drop source → deny access Restrict marked room only → deny access Minimize all room only → deny access
PythonIn [13]Expand
assert before == [
(Decision.DROP_SOURCE, {}),
(Decision.ROOM_ONLY, {"room": "E2"}),
(Decision.ROOM_ONLY, {"room": "E2"}),
]
assert after == [(Decision.DENY_ACCESS, {})] * len(Strategy)A permission check does not withdraw data a reader has already seen. If there is a separate display boundary, the deployment has to model what happens to stored results and queued output when access changes. The code evaluates a model-facing view once for each already-loaded row and reevaluates it when the test gives it a new permission set.
Trace one replay without losing the reason
Read the test case after deciding which value is held fixed. The row remains the same visitor guide. The source identifier, room and mark are identical before and after. The strategy may vary across the rows of the printed table but is fixed within each row's before-and-after comparison. The change is the assignment of visible source identifiers. A transition from room only to deny access is therefore evidence about the local decision rule's dependence on current access for that same record.
A useful negative check observes whether denied rows produce any context fields. An application may write a denial reason while inadvertently retaining a selected field in the object used for rendering. The returned pair lets us test the reason and the data independently. For a production test, observe the same property at the actual boundary where information is disclosed. Testing the return value of a helper verifies that helper only. When a separate display stage or a cross-request cache exists, the boundary extends beyond the helper.
Consider what it means for a guide to be the only useful evidence in this run. If access is still present and the policy drops the marked guide, the system cannot use the guide's room value. A fallback could show that the result is unavailable and allow the reader to select a different known source. It should preserve reads within the reader's scope, even when someone requests review. Recovery and escalation deserve explicit permission checks because they may involve a different human operator or a different view of the record.
Another useful replay holds authorization fixed while changing the content label. Start with a named guide with the same title and room. Feed the view builder a clear mark and the instruction-like mark in separate tests, for each strategy. If the policy changes from a full view to a room-only view, that transition is about selection. Access to the source identifier has not changed. If authorization changes in this replay, the application has combined decisions that we meant to keep independent.
You can use these exercises during a local release review with both results and assumptions visible. A duplicate source identifier, an unknown strategy, or a schema error are different scenarios. The code uses fixture objects defined in the notebook and checks uniqueness of their identifiers. A deployable pipeline would have to decide what happens when record resolution fails or when multiple copies have different access decisions. Make that rule explicit before accepting ad hoc behavior as an implementation detail.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!