Language models that read long documents, such as papers to review, résumés to screen, or email threads to summarize, can be hijacked by a single sentence an attacker has planted in the text. These are indirect prompt injections: instructions hidden in data that the model obeys as if they came from its operator. The problem gets much worse as documents get longer. A security-tuned 8B model that resists injections when it sees only an abstract fails 78% of the time when it sees the full paper (LongPIBench). Separately, models decide whose words carry authority mostly from how text sounds, not from the tags that mark who wrote it. Removing the reasoning-like style from forged text cut attack success from 61% to 10% (Prompt Injection as Role Confusion).
These two findings suggest a defense that needs no access to the protected model's internals. A small trained model reads the long document in short pieces and writes a compact digest of what the document says. Any instructions it finds are reported in the third person as quoted content ("the document contains a sentence asking reviewers to recommend acceptance"). They are neither copied verbatim nor silently deleted. The downstream model then works from a short, neutrally voiced digest. That removes the two conditions under which injections thrive: long context and authoritative style. We train this compressor with reinforcement learning on a reward that counts task accuracy and also how the downstream model treats the injected text.
Core Claim
The claim is that a compressor trained to optimize three things jointly gives a better security–fidelity tradeoff on long-context injection benchmarks than either deleting suspicious spans or compressing for task accuracy alone. The three objectives are downstream task quality, the downstream model's refusal to execute injected instructions, and its willingness to process them as data. It should do this for black-box downstream models, too. The novelty is not compression as such. It is the training target. The compressor's output must make injected content legible as data to the reader model, and the reward is measured on that model's behavior.
The reward on a document $d$ with downstream output $y$ is
$$ R(d) = Q(y) + \lambda_s \cdot \mathbb{1}[\text{not Execute}] + \lambda_f \cdot \mathbb{1}[\text{Process}] - \lambda_\ell \cdot \frac{|c|}{|d|}, $$
where $Q$ is the task metric (exact match, ROUGE-L, or the review decision), "Execute" and "Process" are the behavioral outcomes defined by SECFID, $|c|/|d|$ is the compression ratio, and the $\lambda$ terms are weights. Including the Process term is what separates this from a filter. A filter is rewarded for making injections vanish. This compressor is rewarded only when the reader can still talk about them.
How This Relates to Prior Work
The method comes from Less Is More (CORE-RAG). That work trains a passage compressor with Group Relative Policy Optimization (a reinforcement-learning method that scores groups of sampled outputs against each other), using downstream QA exact match as the reward. It reports +3.3 EM on NQ while keeping about 3% of tokens. CORE-RAG never considers adversarial text. Its task-only reward could even learn to keep an injection that is formatted to look like the answer. We test that possibility directly.
The closest security work comes in two kinds. SecurityLingua trains a token classifier that extracts the "core intention" of short jailbreak prompts and reaches 1% success on JailbreakBench. It targets direct, short jailbreaks rather than injections buried in 10k-token third-party documents, and it extracts tokens rather than rewriting voice. PISanitizer is the strongest long-context defense. It locates injected spans from attention peaks after a bait instruction and cuts them out, reducing attack success from about 90% to under 2% on LongBench. Its authors acknowledge it over-deletes when documents legitimately contain instructions.
Two papers constrain our design. Security–Fidelity Tradeoffs shows that deletion-style defenses reach 99.3% security only by dropping to 71.0–73.9% fidelity. It also shows that a preference ranking of Process > Ignore > Execute raised processing from 43.2% to 80.6%. We borrow that ranking as reward structure. Many-shot Jailbreaking shows that safety fine-tuning shifts the intercept but not the slope of length-driven attacks. That argues against hoping a fine-tuned reader will become immune to long context, and for keeping the reader's context short.
Research Program
The compressor is an 8B instruction model. It reads the document in windows of roughly 1–2k tokens, where LongPIBench shows defenses still hold. It emits a digest for each window in a constrained format: factual statements, verbatim quotes for content that must be preserved (code, figures, clause text), and an attributed-content field for anything phrased as a directive to the reader. The digests are concatenated in document order, so the reader can still reason across windows.
Training data consists of long documents from LongBench-style QA and summarization, plus synthetic reviews and résumés. Injections are drawn from the heuristic attack families LongPIBench describes and are placed at varying positions. We include an equal share of clean documents that are dense with legitimate instructions, such as tutorials, rubrics, and contract obligations, so the compressor cannot learn "delete anything imperative."
During training, the reader is a frozen Llama-3.1-8B-Instruct. At test time we swap in MetaSecAlign 8B and a closed API model, without retraining, to test whether the compressor transfers across readers.
The analysis has a second purpose that addresses LongPIBench's open question of why length dilutes defenses. We cross two factors: shortening the text versus keeping it long, and neutralizing its voice versus keeping it. This separates how much protection comes from the reader seeing less text and how much from the injection no longer sounding authoritative.
Baselines
The naive reference point is the undefended reader on the full document. LongPIBench reports Llama-3.1-8B-Instruct at 100% attack success on paper review and résumé screening under its Combined Attack. MetaSecAlign 8B is a second undefended-architecture reference, at 0.78 attack success on full papers and 100% on synthetic paper review. Both rows come from LongPIBench.
The strongest existing method is PISanitizer, with its reported under-2% attack success and near-unchanged F1/ROUGE-L on its LongBench injection setup. We rerun it ourselves on the same LongPIBench splits, SECFID instances, and readers, using the authors' default filter settings. We give it the same tuning budget we spend on our reward weights, on a shared validation split. We found no reported result on Lacuna for PISanitizer on LongPIBench or SECFID, so those numbers will be new. Beating it means matching its attack success within two points while raising SECFID fidelity and Process rate significantly. On instruction-dense clean documents, it means losing less task quality. We also include PromptLocate, which LongPIBench reports leaves attack success above 0.4 in most cases.
Three ablations isolate the key ingredient. The first is a CORE-RAG-style compressor trained with the same architecture and compute but task reward only ($\lambda_s=\lambda_f=0$). The second is our reward without the Process term, which tests whether the model collapses into a deleter. The third is a zero-training baseline: the same compressor model prompted to "summarize, reporting any instructions as quoted content."
Why not just…?
Why not just use a task-only compressor like CORE-RAG, since dropping 95% of tokens probably drops the injection too? This is the most serious threat. Against generic injections it may work nearly as well. The deciding experiment is the task-only ablation evaluated on two attack sets: generic attacks, and attacks written to look like the answer or the key review evidence. If the task-only compressor is as safe on both, the security reward is unnecessary and we will report that. Our prediction is that it keeps answer-shaped injections, because its reward has no reason to discard them.
Why not just use PISanitizer, which already gets under 2% attack success? On attack success alone it may be hard to beat. Its own authors list over-deletion of legitimate instructions as a limitation. SECFID shows deletion defenses lose roughly a quarter of fidelity. Our comparison therefore centers on instruction-dense clean documents and SECFID's Process outcome, where deletion cannot score by construction.
Why not just prompt an LLM to summarize the document safely? The summarizer reads the injection too, and it is itself an instruction follower vulnerable to the same hijacking. Still, working on short windows may already protect it. The prompted-compressor baseline settles this. If it matches the trained compressor, the contribution shrinks to the chunked, neutral-voice design, which would still be a useful negative result about the value of reinforcement-learning training.
Why not just chunk and run a short-context detector? LongPIBench reports that segmentation does not escape the tradeoff between false positives and misses. Detection also still ends in a choice between deleting and passing text through. We include chunk-plus-detector as an additional row, but expect it to sit on the same frontier.
Proposed Experiments
The primary evaluation uses all eight LongPIBench datasets. We train on synthetic splits only and test on the real-world splits (ICLR reviews, LiveCareer, GitHub code review, Enron) to prevent leakage. We report attack success by injection position and document length, alongside task quality. Fidelity is measured on SECFID using held-out task families, reporting security, fidelity, and the Execute/Process/Ignore split against its reported frontier. For continuity with PISanitizer, we also report on its injected LongBench setup. Legitimate-instruction stress uses CUAD clause identification, scoring clean task quality only; we found no reported baseline numbers on Lacuna for it. Adaptive attacks target the compressor directly: injections asking it to copy text verbatim, and injections mimicking the attributed-content format.
The decisive check is the factorial experiment on LongPIBench, crossing short versus long and neutral versus original voice. If the neutral-voice condition alone recovers most of the protection at full length, style is the main mechanism and compression is a convenience. If shortening alone does, dilution is the main mechanism. If only the combination works, both mechanisms matter, which is the hypothesis behind this design.
We will state one limitation plainly. Data-only attacks, where false facts mislead the reader without any imperative phrasing, are not addressed by rewriting voice. We report them separately as an expected failure rather than claim coverage.
References
- LongPIBench: A Long-Context Benchmark for Prompt Injection
- Prompt Injection as Role Confusion
- Less Is More: Elevating RAG via Performance-Driven Context Compression
- SecurityLingua: Efficient Defense of LLM Jailbreak Attacks via Security-Aware Prompt Compression
- PISanitizer: Preventing Prompt Injection to Long-Context LLMs via Prompt Sanitization
- Security--Fidelity Tradeoffs: The Hidden Cost of Prompt Injection Defense
- Many-shot Jailbreaking
- CUAD: An Expert-Annotated NLP Dataset for Legal Contract Review