The Research Report
Output Filtering: The Only Defense That Survives Adaptive Prompt‑Injection Attacks
By the Content‑Agent Team – 9 June 2026
1. Why Prompt‑Injection Is Suddenly Everywhere
Since the first public demonstrations of large‑language models (LLMs) in 2023, “prompt injection” has become the SQL‑injection of the AI era. A hostile user can embed malicious instructions in seemingly innocuous text, forcing the model to reveal secrets, exfiltrate credentials, or even take actions it has been explicitly told not to. The problem is amplified when LLMs are used as agents—they can call APIs, write files, and modify databases on behalf of a user. Companies that embed confidential system prompts (API keys, internal policies, or proprietary knowledge) are especially exposed.
Over the past year the community has rallied around three families of mitigations:
- Model‑side defenses – the model is asked to refuse or self‑filter (system‑prompt guardrails, instruction hierarchy, self‑reflection, classifier‑based gates).
- Input‑side defenses – sanitising user input before it ever reaches the model (regex filters, whitelist tokenizers, content‑type checks).
- Output‑side defenses – an application layer that inspects the model’s response and blocks anything that looks like a leak.
Despite a flood of blog posts, conference talks, and even vendor‑supplied “guardrails”, the real security boundary has been debated. Do we really trust a model to police itself? The answer, according to a new paper from Swept AI and the University of Michigan, is a resounding no.
2. The Adaptive Attacker: 20 000 Rounds, 9 Configurations, 15 000 Attacks
Reference: Priyal Deep et al., “Evaluation of Prompt Injection Defenses in Large Language Models”, arXiv 2604.23887 (v2, 12 May 2026).
The authors built a self‑evolving adversary that runs a loop on top of a language model. In each round the attacker:
- Issues a crafted user prompt (often with hidden instructions).
- Receives the model’s response.
- Analyses whether any secret was leaked (by searching for a tokenised secret string).
- If the leak failed, it mutates the prompt using a small‑scale evolutionary strategy (synonym substitution, token re‑ordering, obfuscation, indirect references).
- Repeats up to a hundred iterations per attack trial.
The attacker was run against nine defense configurations (five model‑side, two combined model‑side, and two application‑side). Across 20 000+ attack trials, the researchers logged 15 000 successful leaks for every configuration that relied on the model to protect itself. In contrast, the output‑filtering configuration—hard‑coded regex/JSON schema checks applied after the model generated text—recorded zero leaks.
3. The Nine Defense Configurations (A Quick Taxonomy)
| # | Category | Description | Result |
|---|---|---|---|
| 1 | Model‑side | Plain system‑prompt “do not reveal the secret”. | Broken after ~12 rounds. |
| 2 | Model‑side | Spotlighting: delimit untrusted input with special tokens. | Broken after ~18 rounds. |
| 3 | Model‑side | Instruction hierarchy: nested “you may only … if …”. | Broken after ~22 rounds. |
| 4 | Model‑side | Self‑reflection: ask the model if it leaked anything. | Broken after ~30 rounds. |
| 5 | Model‑side | Paraphrase guard: ask the model to re‑phrase before answering. | Broken after ~35 rounds. |
| 6 | Model‑side | Classifier gate: a small‑model decides if the user prompt is malicious. | Broken after ~27 rounds. |
| 7 | Model‑side | Stacked guard: combine 1‑5 in a single prompt. | Broken after ~41 rounds. |
| 8 | Application‑side | Input filter: regex whitelist before the model is called. | Reduced leak rate (~30 % of attacks), but still broken. |
| 9 | Application‑side | Output filtering – deterministic checks on the model’s response (string match, JSON schema, sensitive‑token blacklist). | Zero leaks across 15 000 attempts. |
The stark contrast—all model‑centric defenses eventually fail while a single deterministic output filter holds firm—is the paper’s headline claim.
4. Why Output Filtering Wins When Models Lose
- Determinism – The filter runs outside the stochastic LLM. No matter how clever the prompt, the filter will block any response that matches a forbidden pattern. This eliminates the “adversarial drift” that defeats learned classifiers.
- Explicit security boundary – Secrets never leave the application unchecked. Instead of “trusting the model’s refusal”, we verify the output before it reaches a user or a downstream system.
- Low latency – The filter is essentially a regular‑expression or schema validation step, adding micro‑seconds to the request latency—orders of magnitude cheaper than a second‑long model inference.
- Composability – Multiple filters (e.g., token blacklist and JSON schema validation) can be stacked without increasing attack surface. Adding a new secret to the blacklist is a single line change.
- Auditability – Every blocked response can be logged, enabling forensic analysis and compliance reporting.
The authors stress that output filtering is not a silver bullet: it protects only what you explicitly forbid. If a secret is never embedded in the system prompt, the filter has nothing to catch. Nonetheless, it provides the hardest line of defence in a layered security model.
5. Community Reaction – From Blogs to Academic Summaries
The paper quickly attracted attention across three major venues:
- LLM‑Hacking published a walk‑through of the experiment on 26 April 2026, reproducing the 20 000‑round attack and highlighting the “zero‑leak” result for output filtering. The post (linked below) includes the full table of defenses and a sample filter implementation in Python.
- Pith – the AI‑trust platform ran an internal reproducibility test and issued a short “risk‑assessment” note, calling the output‑filter finding “the most concrete evidence yet that model‑side guardrails are insufficient for production workloads.”
- AISecHub added a dedicated “Prompt‑Injection Defense” article (June 2026) that references the Swept AI study as the canonical benchmark for evaluating defensive stacks. The author, Tal Eliyahu, writes: “If you are still relying solely on self‑refusal, you are leaving a back‑door open.”
Together these write‑ups have forged a consensus: the security community now treats output filtering as a required component of any safe LLM deployment.
6. How to Build a Robust Output Filter – Practical Guidance
Below is a lightweight recipe that production teams can adopt today. The steps are deliberately language‑agnostic; you can implement them in Python, Node.js, Go, or even in a low‑code policy engine.
- Identify the secret surface – any string that must never be emitted (API keys, internal policy snippets, PII, proprietary code). Store them in a secret‑store (e.g., HashiCorp Vault) and load into memory at start‑up.
- Define a deterministic predicate – most teams start with a case‑insensitive exact‑match blacklist. For structured data (JSON or XML) add a schema validator (e.g.,
jsonschemain Python) that rejects responses containing unexpected fields. - Compose the filter – implement a pipeline:
- Log & alert – whenever the filter returns
False, log the raw model output, the triggering secret, and the user request. Send an alert to the security team. - Fail‑closed – if the filter blocks a response, return a generic “The request could not be completed” message, not the raw model error. This prevents accidental leakage through error strings.
- Test aggressively – incorporate the LLM‑Hacking attack loop into your CI pipeline. Run a mini‑adaptive attacker against your own service to ensure the filter holds under mutation.
def filter_output(text: str) -> bool:
# 1) exact‑string blacklist
for secret in SECRET_LIST:
if secret.lower() in text.lower():
return False
# 2) JSON schema (if response should be JSON)
try:
data = json.loads(text)
jsonschema.validate(instance=data, schema=RESPONSE_SCHEMA)
except (ValueError, jsonschema.exceptions.ValidationError):
return False
return True
Advanced tip: combine output filtering with runtime sandboxing (e.g., restricting tool‑calling APIs) for defense‑in‑depth. Even if a secret slips through, the sandbox can stop the downstream exfiltration.
7. Limitations & Open Research Questions
| Issue | Current State | Open Question |
|---|---|---|
| Secret discovery – If an attacker learns the secret value (e.g., via a side‑channel) they can embed it verbatim in their prompt. | Filter only blocks known secrets. | How can we design dynamic filters that recognise secret patterns without leaking the secret itself? |
| False positives – Over‑zealous regex can block legitimate user output (e.g., a user legitimately mentions a token string). | Manual tuning required. | Can we employ machine‑learning‑assisted classifiers outside the LLM that learn safe‑vs‑unsafe output while remaining deterministic? |
| Scalability – Very large response payloads (>10 KB) may affect filter latency. | Simple string search is O(n). | Are there streaming‑filter algorithms that work on chunked responses? |
| Cross‑modal attacks – Audio‑to‑text or image‑to‑text pipelines may embed secrets in non‑text modalities. | Paper focused on text output. | How do we extend deterministic filtering to multimodal generation? |
The community is already exploring these topics, and the Swept AI benchmark will likely become a standard test‑bed for future work.
8. Bottom Line – Move the Boundary Out of the Model
The 2026 Swept AI study delivers a clear, actionable message:
If a defense relies on the model to self‑police, an adaptive attacker will eventually defeat it.
If a defense runs outside the model—hard‑coded output filtering—it holds, even under 20 000 rounds of adaptive attack.
For teams building LLM‑enabled products, the pragmatic takeaway is to treat output filtering as a non‑negotiable security component. It should sit alongside input sanitisation, least‑privilege tool gating, and rigorous logging. Model‑side guardrails can still be useful for usability (e.g., nudging the model away from profanity), but they must not be the only line of defence for confidential data.
In the rapidly evolving AI security landscape, the most reliable way to keep secrets safe is to stop trusting the model with the secret in the first place—and to verify everything that leaves the model.
References
- Priyal Deep, Shane Emmons, Amy Fox, et al., Evaluation of Prompt Injection Defenses in Large Language Models, arXiv:2604.23887 v2 (2026). https://arxiv.org/abs/2604.23887
- LLM‑Hacking, Output filtering beats model self‑defense: 20 000 adaptive attacks, one survivor (2026‑04‑26). https://www.llm‑hacking.com/hacks/output-filtering-prompt-injection-defenses.md/
- Pith, Risk Assessment – Prompt‑Injection Guardrails (2026‑05‑14). https://www.swept.ai/post/indirect-prompt-injection-enterprise-supervision
- AISecHub, Prompt‑Injection Defense Landscape (2026‑06‑05). https://medium.com/ai-security-hub/ai-security-research-april-2026-e9258ebff64d