Indirect Prompt Injection › The policy engine
Language AI HandbookAll chapters The fixture starts with an evidence row already in memory. Its access check uses the source identifier and the permission state supplied by the application before building a model-facing view. A row that fails this check produces a denial for every strategy. In a deployment, authorize acquisition at retrieval and enforce the applicable audience conditions again at display. The code then chooses how many fields the caller may use for the answer. The returned decision says what the policy permits for a row. A later component has to build the context from that decision.
PythonIn [7]Expand
def decide(
row: Evidence, visible_sources: frozenset[str], strategy: Strategy
) -> Decision:
if row.source_id not in visible_sources:
return Decision.DENY_ACCESS
if strategy is Strategy.MINIMIZE_ALL:
return Decision.ROOM_ONLY
if row.mark is ContentMark.INSTRUCTION_LIKE:
if strategy is Strategy.REJECT_FLAGGED:
return Decision.DROP_SOURCE
return Decision.ROOM_ONLY
return Decision.ROOM_AND_TITLEThe order of these checks is part of the design. If a marker changes, the authorization result for the same caller and row stays the same. The selected fields can still change for an authorized row. In production, permission state and the record identifier must come from application-controlled identity and resource resolution. A policy model for that wider system needs to state when it reevaluates permission. The NIST zero-trust reference architecture describes ongoing evaluation and revocation when policy requires it. NIST zero-trust reference architecture
PythonIn [8]Expand
all_visible = frozenset(fixture.evidence.source_id for fixture in fixtures)
example_row = fixtures[1].evidence
assert all(
decide(example_row, frozenset(), strategy) is Decision.DENY_ACCESS
for strategy in Strategy
)What the decision is allowed to depend on
Each policy rule should have a clear input contract. Our rule receives one evidence row, a set of current source permissions, and a strategy name. It returns a decision. The acceptable branches for a current authorized reader are enumerated. There is a direct denial when the source identifier is absent. The policy has no model callback or arbitrary action hook. That makes the test an exercise in permission and data selection. In the deployed version, a separate enforceable boundary should ensure that this kind of decision governs the actual read and display.
The code passes an opaque identifier to a set membership check. A source title is human-readable context, and a reader can have access to one guide with that title while another copy has different visibility. Treating the title as the authorization identifier would require a separate uniqueness and authority contract. We avoid that assumption in the fixture. The stable identifier binds current permission to the specific evidence row and is held fixed when we compare withdrawn and granted states.
A production design also needs a rule for concurrency. The application may compute a view while the reader still has access and render it later, after a change. The authorization test should observe whichever operation the design claims to protect. If the product requires revocation before display, validate current display authority when the renderer is about to use the stored view. A read-time test is not sufficient evidence for that claim. If read and display happen in the same authorized session under a documented expiry policy, exercise the expiry boundary separately.
Choose semantics for unavailable permissions with the same care. The empty set in this notebook stands for a successful observation that none of these source identifiers may be read. It is a known state. A failed attempt to load permissions is a different situation, even if both result in no data crossing the boundary. Preserve the distinction in any troubleshooting interface. It can help a maintainer see whether a legitimate source disappeared because permission was withdrawn or a dependency could not decide.
The hard part of keeping access separate from content is wiring. A plugin, background parser or renderer should follow the documented authorization rule for the operation it performs. At each normal entry point, inspect whether an earlier decision still applies. For our room lookup, mark and content selection are later stages. Changing the selected view does not widen which source identifiers the caller can use. Modeling those stages separately lets us record the authorization property independently of the projection implementation.
A reason code is useful to check in tests because it survives even when two paths have the same empty reply. Decide how much reason detail belongs in the user-visible interface. A product can show a simple unavailable answer while retaining a scoped operator event that distinguishes denial from content omission. Think about who may see that detail, especially if the existence of a resource is itself sensitive. This notebook prints the full reason for each artificial row because all fixture identifiers and inputs are available to the reader.
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!