Skip to content

[AI-4201] Prompt injection screen covers images and knowledge - #2708

Open
kanat wants to merge 13 commits into
mainfrom
kanat/ai-4201-screen-images-knowledge
Open

kanat wants to merge 13 commits into
mainfrom
kanat/ai-4201-screen-images-knowledge

Conversation

@kanat

@kanat kanat commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

With the prompt injection screen on, the classifier read only the text of the newest input, so an image never reached it. A knowledge passage was checked only as part of the whole tool result, after the model had started reading it. Now a turn whose newest input has an image is refused with prompt_injection, and each passage a knowledge lookup finds is screened before the model reads it.

How it works

LLM response, prompt_injection on (org or app)
└─ newest input (user turn + tool results since the model last spoke)
   ├─ has an image part      -> refused: prompt_injection
   │  (fail open or closed)     ErrPromptInjection + ErrScreenImages
   │                            no decision model reads images
   └─ text only              -> screened as before

knowledge lookup (lookup tool, or a skill's lookup)
└─ store search returns passages
   └─ each passage (source + text) screened at once, 2s limit
      ├─ reads as an injection     -> left out of the answer
      ├─ could not check, fail closed -> left out
      ├─ could not check, fail open   -> kept
      └─ clean                     -> kept
   answer = kept passages + "The prompt injection screen withheld
            N passage(s) that matched." when N > 0

No classifier here takes an image: a decision model request's state is text or JSON (internal/decisionmodel/decisionmodel.go:127), and every provider sends it as such (gemini/gemini.go:178, systemone/systemone.go:245, which openrouter, perplexity and typesafe wrap). So the screen refuses rather than sends the image anywhere.

Change Result Test
Image in the newest user turn or tool result, screen on refused, prompt_injection, not _unchecked (a retry is refused again); same in fail-open and fail-closed TestAnImageInTheNewestInputIsRefusedSinceTheScreenCannotReadIt
Image, screen on, no decision model on the deployment refused (text alone is not screened there) TestAnImageIsRefusedOnADeploymentWithNoClassifier
Image in a turn the model already answered not refused again TestAnImageTheModelAlreadyAnsweredIsNotRefusedAgain
Image, screen off, or only prompt_injection_fail_closed set not screened, as on main TestNothingIsScreenedUnlessAPolicyTurnsItOn, TestFailClosedAloneScreensNothing
Socket error frame code: prompt_injection, says the screen can't read images TestAnErrorFrameForAnImageTheScreenCannotReadSaysSo
POST /v1/agents/runs 400 prompt_injection, says why TestARunWithAnImageTheScreenCannotReadIsRefusedAndSaysWhy
Stored turn and agent log row refused, with the image reason TestARefusedTurnWithAnImageKeepsThatTheScreenCannotReadImages, TestARuntimeErrorRowForAnImageTheScreenCannotReadSaysSo
Knowledge passage flagged / clean / unchecked refused / passes / follows fail closed TestAKnowledgePassageThatReadsAsAnInjectionIsRefused, TestACleanKnowledgePassagePasses, TestAKnowledgePassageTheScreenCouldNotCheckFollowsFailClosed
Knowledge, screen off or no policies not screened TestNoKnowledgePassageIsScreenedUnlessAPolicyTurnsItOn, TestADeploymentWithNoPoliciesScreensNoKnowledge
Lookup with one, or every, passage refused the rest is answered, with a note of how many were withheld TestALookupLeavesOutAPassageTheScreenRefusedAndSaysSo, TestALookupWhoseEveryPassageWasRefusedSaysHowMany
Lookup the screen passes the answer is the same as with no screen TestALookupTheScreenPassesIsAnsweredWhole
Passage flagged for its text, not its source left out TestALookupWithholdsAPassageTheScreenRefusedForItsText
Whose policy screens a passage the session's own app TestThePassageScreenIsAskedAsTheAgentsApp
Session built by the manager, app with the screen on / app without flagged passage left out / every passage given TestKnowledgeScreenSuite (integration)
No classifier, screen fails open passage passes with no warning per lookup, as Screener does TestAPassageIsLetThroughQuietlyWithNoClassifierWhenTheScreenFailsOpen

Behaviour change

An app with prompt_injection on can no longer send photos, camera or video frames, or tool screenshots to its agent: every such turn is refused. The prompt_injection field description and the router README say so. With the screen on, a lookup also waits for the passage screen, at most 2s, before the model gets its answer. Nothing changes for an app with the screen off. The field description changed, so every client is regenerated.

Follow-up

A refused image turn still reaches the provider. The request, image included, is sent and billed before the screen closes the stream, even though the refusal is already known. Refusing before the model call changes how the refusal reaches the agent, the recorder and the quota hold, so it is a follow-up ticket and not part of this PR.

Detail is in AI-4201.

Tests, mutations, review rounds and commands

Base probe on 6dff757 (a throwaway test in a scratch worktree): with the screen off an image turn got no verdict; with the screen on an image alone got no verdict, and an image with a caption passed a clean classifier. The control tests take "no verdict with the screen off" from that probe.

First mutation run, 19 mutants, all killed by the tests in the table above:

Mutant Killed by
image check off TestAnImageInTheNewestInputIs..., TestAnImageIsRefusedOnADeploymentWithNoClassifier
image check reads all history TestAnImageTheModelAlreadyAnsweredIsNotRefusedAgain
image refusal without ErrPromptInjection TestAnImageInTheNewestInputIs...
image refused with the screen off TestNothingIsScreenedUnlessAPolicyTurnsItOn, TestFailClosedAloneScreensNothing
knowledge screen ignores the policy TestNoKnowledgePassageIsScreenedUnlessAPolicyTurnsItOn
knowledge screen never / always fails closed TestAKnowledgePassageTheScreenCouldNotCheckFollowsFailClosed
no nil check on the enforcer TestADeploymentWithNoPoliciesScreensNoKnowledge
agent drops ScreenKnowledge TestALookupLeavesOutAPassage...
reader calls a nil screen panic in the lookup tests without a screen
reader keeps refused passages / reports none withheld TestALookupLeavesOutAPassage..., TestALookupWhoseEveryPassageWasRefused...
note for one / for many off by one the same two
source not screened the same two
run, socket, log row, stored turn: image branch off the test for that caller in the table above

Final mutation run, on head 52606f6a5, one mutant at a time, each restored after its run. Every mutant failed the test named:

Mutant Killed by
passage screened by its source only TestALookupWithholdsAPassageTheScreenRefusedForItsText
agent asks the screen with an empty owner TestThePassageScreenIsAskedAsTheAgentsApp (agent), TestAnAppWithTheScreenOnIsNotGivenAFlaggedPassage (session)
manager wiring line removed (no screen built) TestAnAppWithTheScreenOnIsNotGivenAFlaggedPassage (two apps)
manager passes a nil screen TestAnAppWithTheScreenOnIsNotGivenAFlaggedPassage (two apps)
screen flag ignored TestAnAppWithoutTheScreenIsGivenEveryPassage (two apps)
count is len(found) + withheld TestALookupLeavesOutAPassageTheScreenRefusedAndSaysSo
fail-open early return removed TestAPassageIsLetThroughQuietlyWithNoClassifierWhenTheScreenFailsOpen
fail closed only when classifier == nil TestAKnowledgePassageTheScreenCouldNotCheckFollowsFailClosed
run message without "or turn off prompt_injection" TestARunWithAnImageTheScreenCannotReadIsRefusedAndSaysWhy
error frame without the next step TestAnErrorFrameForAnImageTheScreenCannotReadSaysSo

owner.CustomerID == "" in KnowledgeScreen is equivalent: it only skips a policy read for an owner with no app.

Review rounds:

  • Round 1: NO-GO from the main reviewer and from the security reviewer. They asked for the screen wiring to be tested with two apps, the passage count to be pinned, the field description to name photos, camera frames and screenshots, and the refused-image call to stop before the provider. The first three are fixed in this PR. The last is the follow-up above.
  • Round 2: GO from the delta reviewer on 52606f6a5, with the mutants above run on that head.

Suites: go test ./internal/policy/ ./internal/agent/ ./internal/session/, go test -tags integration ./internal/policy/ -run TestPolicySuite, go test -tags integration ./internal/api/ -run 'TestRunsSuite|TestAnErrorFrame', go test -race ./internal/agent/ -run TestAgentSuite -testify.m Lookup. All pass. Clients regenerated with the commands in acceleration/README.md; Swift, Kotlin, Dart and Ruby output did not change, since none of them carries this field's description in full.

🤖 Generated with Claude Code

kanat and others added 5 commits November 29, 2026 10:40
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Text review: 10 unclear of 15

The caller-facing text is the part that matters here: an app developer with the screen on must learn that a request with an image is refused, and what to do about it. Today the policy field says it in its fourth sentence, the run refusal gives only one way out, and the socket refusal gives none.

[Should fix] T1.1 (field description, acceleration/internal/api/policies.go:37): the prompt_injection description opens with "Screen what every LLM response is asked for prompt injection", which reads two ways, and it packs the delay, the held response, the image refusal and the knowledge passages into one paragraph. Suggested wording (regenerate openapi.yaml and the clients after):

Check what each LLM response is about to read for prompt injection: the user's turn and any tool results. The check runs while the model answers, so it adds nothing to time to first token. If the input reads as an injection, the response fails with prompt_injection before its tool calls can be acted on. The check can't read images: a response whose newest input has an image fails with prompt_injection too, so leave images out while this is on. A passage a knowledge lookup finds is checked before the model reads it, and a passage that reads as an injection is left out of the lookup's answer.

[Should fix] T1.4 (docs, acceleration/README.md:539): one table cell packs five cases, and "fails closed" is not explained there. Suggested wording for the cell:

Screens the newest input of every LLM response (the user's turn and any tool results) for prompt injection. The decision model router reads it on its default route (Jev), while the model answers. Deltas are not held; the end of the response waits for the verdict (at most 2s), and an injection fails the response before its tool calls can be acted on. The decision model reads text only, so a newest input with an image (a photo, a video frame or a tool's screenshot) is always refused, even when the policy does not fail closed. Each passage a knowledge lookup finds is screened before the model reads it. A flagged passage is left out, and the model is told how many were withheld.

[Nit] T1.7 (comment, acceleration/internal/policy/injection.go:93-97, partly outside the diff hunk): four cases in one paragraph. Suggested wording:

Screener returns the llmrouter.Screen that checks the newest input of a response for prompt injection while the model answers it. It does nothing for a customer whose policies do not turn the screen on. A newest input with an image is always refused, since the classifier cannot read it. With no classifier, a response is refused if the policies fail closed and passes otherwise.

[Nit] T1.8 (PR opening): the third sentence carries two changes and two outcomes. Suggested opening:

With the prompt injection screen on, the classifier read only the text of the newest input, so an image never reached it. A knowledge passage was checked only as part of the whole tool result, after the model had started reading it. Now a turn whose newest input has an image is refused with prompt_injection, and each passage a knowledge lookup finds is screened before the model reads it.

Comment thread acceleration/internal/api/policies.go Resolved
Comment thread acceleration/internal/api/runs.go Resolved
Comment thread acceleration/internal/api/runs.go Resolved

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: NO-GO

Reviewed 28e1c94 (already on the current main, 6dff757). The image rule and the knowledge rule both work, and with the screen off nothing changes. Two Should fix items block the merge: four mutants survive on the new knowledge wiring (R1.1), and the API field description does not tell an app that camera frames and tool screenshots count as images (R1.2).

Checked and sound

  • Touched suites pass: unit policy, agent and session; integration TestPolicySuite, plus TestRunsSuite and TestAnErrorFrame* in api. The pr-review generated.sh check reports every generated file in step with openapi.yaml.
  • Screen off: Screener returns before any new code, as on main. With every verdict nil, the lookup reader returns what main returned: same passages, same order, no note, same LookedUp count.
  • Clean input still passes: a clean passage (fail closed on), a clean text turn, and an image the model already answered. The lookup tool and a skill's lookup share one reader, so both are covered.
  • A refused image turn leaves the history, so the next text turn is not refused again (agent.go:699, agent.go:3805).
  • The /stream socket uses the same refusalText/withRefusal, so it gets the image wording too.
  • The author's equivalent mutant (owner.CustomerID == "" in KnowledgeScreen) is accepted. Screener has the same guard.
  • Mutations: 12 run by this review, 6 survived (4 in R1.1, 1 Nit R1.5, 1 equivalent).

Nits for tickets

  • R1.4 (internal/llmrouter/session.go:640-655): the image verdict is known before the model is called, but the router still sends the image to the provider. The call is billed before the stream is closed. A screen that has already refused could skip the provider call.
  • Author question 2 (screening web search results one by one) goes to a ticket, as decided.

CI: this is a draft, so the go, unit and integration jobs were skipped on this head. They run at gh pr ready.

Verdict: request changes, for R1.1 and R1.2.

Comment thread acceleration/internal/api/policies.go Resolved

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[security R1] VERDICT: NO-GO (one Should fix)

I reviewed who can reach what: the image refusal on every screened response, the knowledge screen on lookups, the refusal text callers get, and the policy read behind both.

Id Severity Where What
S1.1 Should fix internal/agent/agent.go:873, internal/session/manager.go:979 No test proves the knowledge screen is wired in production or asked as the session's app. This is the same gap as R1.1, and one test closes both.
S1.2 Nit internal/policy/injection.go:213 A passage is judged whole within the 2s screen timeout, while documents are judged in pieces. Ticket.
S1.3 Nit = R1.4 The image refusal is known before the model call, but the request still goes to the provider.
S1.4 Nit = R1.3 One warning is logged per passage when there is no classifier and the screen fails open.
What I checked and found fine
  • Images in other places: older turns keep no images (a photo is kept only for its reply, and a refused turn is withheld with its parts). Tool results with pictures, the vision skill and video captured for a skill all put the image in the newest input, so they are refused. Runs take no history. Message parts are only text or image, attached documents are text screened once on arrival, and text that looks like a data URL stays text to every provider.
  • Child agents: sessions build agents in one place, and subagent lookups use the same screened lookup.
  • Other knowledge sources: lookup is the only reader of the knowledge store, so there are no pinned or preloaded passages to cover.
  • Withheld note: it gives only a count, with no passage text, source or harm names.
  • One passage blocking lookups: only the app's backend writes knowledge. A flagged passage drops out of the lookups that return it and takes one of at most 5 slots. Before this PR, the same passage refused the whole reply, so this narrows the effect.
  • Spend: each lookup costs at most 5 more classifier calls. They run at once, are bounded by the screen timeout and are charged to the app.
  • Policy read: it is keyed by the session's app id, and the owner comes from the session's own options.
  • Error text: the diff has no err.Error() or %v err text reaching callers. The new refusal messages are fixed text.
  • Screen off and rollback: with the screen off, both screens return nothing. There is no migration, so a rollback only drops the new refusals.
  • Author questions: keep refusing camera frames and tool screenshots, because exempting them would let any picture reach the model unscreened. Web search results get their own ticket.

Comment thread acceleration/internal/agent/agent.go Resolved
kanat and others added 8 commits November 29, 2026 11:26
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…creen fails open

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kanat

kanat commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator Author

Round 1 fixes for the items in the review bodies:

  • T1.4: fixed in c742dde. The README row is now short sentences, names prompt_injection_fail_closed instead of "fails closed", and lists a photo, a camera or video frame, and a screenshot a tool returns.
  • T1.8: the PR opening now uses your three sentences.
  • R1.4 / S1.3: left for a ticket. Refusing before the provider call means Create returns an error instead of a stream that fails. The refused-turn handling in the agent, the recorded refusal and the released reservation all read the stream's failure today, so the change reaches several callers and is more than a small fix.

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: GO

Delta review of 52606f6 (was 28e1c94), on main 6dff757. Every earlier Should fix is fixed; no new findings.

Finding Status Check
R1.1 / S1.1 (knowledge screen wiring, owner, text) fixed Five mutants each fail a named test: screen only the source, empty owner (agent and session), wiring line removed, KnowledgeScreen(nil), screen flag ignored
R1.5 (Documents count) fixed len(found)+withheld fails TestALookupLeavesOutAPassageTheScreenRefusedAndSaysSo
R1.3 / S1.4 (quiet skip with no classifier) fixed Removing the early return fails the new policy test; widening it to fail closed fails ...FollowsFailClosed
R1.2 / T1.1 (field description, clients) fixed The description names photos, camera and video frames, and tool screenshots. generated.sh on the head: in step
T1.2, T1.3 (messages say what to do) fixed Whole strings pinned; a mutant without the next step fails each
T1.4 to T1.8 (README row, comments, PR opening) fixed Each claim read against Screener, KnowledgeScreen and runs.go; the README makes no claim about speech-to-speech agents
R1.4 / S1.3 (refuse before the provider call) ticket accepted The reason holds: the agent reads a refusal from the stream's ResponseFailed, and the quota hold is released only for a stream that was not handed over

Runs: vet (plain and integration) and unit suites for policy, agent, session, api and llm are clean. Integration TestPolicySuite, TestKnowledgeScreenSuite, TestRefusedReviewSuite, TestRunsSuite and TestAnErrorFrame pass; the knowledge suites also pass under -race with repeats. 11 mutations checked, 0 survived. The PR is a draft, so CI is skipped.

@kanat
kanat marked this pull request as ready for review November 29, 2026 17:04

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant