Layered inspection protects retrieval chatbots from concealed prompt injections
Verifying text across the prompt, assembled context and generated output prevents hostile reference documents from hijacking automated software assistants.

When a conversational software model reads a database record or a web page, it processes instructions and raw data in the exact same channel.12 Because modern systems parse both kinds of text as natural language strings, an embedded command inside an ordinary document can disguise itself as a system directive, taking control of the assistant without the user realizing anything went wrong.31
Security researchers refer to this blind spot as the semantic gap, where software cannot distinguish between administrative rules and untrusted input.3 The risk multiplies in retrieval-augmented generation, a technique where a chatbot fetches outside documents to answer user questions.42 If an attacker places a hostile instruction inside a shared knowledge base, every subsequent person whose query retrieves that document risks triggering the attack.51
In a preprint posted to arXiv on August 27, 2026, researchers Gulshan Saleem, Nisar Ahmed, Muhammad Imran Zaman, Ali Hassan, and Umar Mujahid presented a three-layer security framework designed to intercept both direct and indirect prompt injections throughout the inference pipeline.5
Why do retrieval systems struggle with hidden instructions?
Retrieval-augmented chatbots fail against hidden text because traditional security tools operate at disconnected points in the processing flow.5 An input filter examines what a user types into the prompt window, but it never inspects the external reference articles pulled from a vector store moments later.5 Similarly, an output monitor checks the final generated response for policy violations, but it cannot prevent a malicious payload from entering the prompt context and steering the model in the first place.5
To execute an indirect injection, an attacker only needs to leave an instruction such as a request to ignore previous guidelines inside a document that an automated assistant will later fetch.32 When a legitimate user asks a related question, the retrieval mechanism gathers the poisoned document and concatenates it into the prompt.42 The language model then reads the attacker text as an authoritative command, leading to unauthorized actions, altered responses, or leaked system rules.43

For an injection to succeed in a retrieval engine, several events take place sequentially. First, an adversary plants an imperceptible or deceptive sentence into an external knowledge source. Next, an ordinary user submits a query that activates the search index, retrieving that stored file into the conversational window. The application software then fuses the retrieved material directly alongside internal system instructions. Finally, the underlying neural network processes the entire package as an undifferentiated stream of words, executing the hidden directive as if an administrator had written it. Halting this progression requires checking the stream before the model interprets the commands.
How does the three-stage pipeline intercept attacks?
The proposed defense intercepts hostile payloads by placing distinct filters at the input stage, the context assembly stage, and the final generation stage.5 The framework acts as model-agnostic middleware, functioning between the user and the language model without requiring any changes to the underlying model weights.5
At the first layer, the system screens incoming user prompts using a rule-based pattern library alongside a fine-tuned semantic anomaly classifier to catch overt manipulation attempts.5 At the second layer, the system organizes the retrieved context by enforcing a provenance-based instruction hierarchy, ensuring that retrieved reference material cannot override the system instructions set by the system operator.5 At the third layer, an output auditing engine applies a policy rule engine and a semantic drift detector to inspect the completed response before it reaches the user.5 A continuous audit loop records structured logs to help retrain the classifiers against emerging attack patterns.5
The second layer focuses specifically on the authority granted to outside records during context construction. Ahmed, a co-author of the preprint, said in response to questions from Primary that this stage treats retrieved text as inherently untrusted data regardless of its phrasing. In Ahmed's words, the mechanism assigns explicit privilege tiers where operator instructions occupy the highest rank, so that even if an excerpt claims to be an administrator message, its original provenance remains unchanged. Ahmed cautioned that this structural separation does not make the hierarchy absolute on its own, because the final interpretation still depends on the language model, making the subsequent output audit essential.
The researchers found that the interaction between the final two stages provided the strongest safeguard. Ahmed told Primary that what surprised him most was how the second and third tiers worked together during ablation tests, noting that when hostile material slipped past context constraints, the output auditor still managed to detect and block the downstream effect.
What can the experimental results tell developers?
Evaluating the multi-layer framework across 5,080 test samples demonstrated that combining defenses across stages sharply reduces vulnerability compared to isolated filters. The authors tested their system against three distinct language models: GPT-4o, Llama 3, and Mistral 7B.

Across the 5,080 evaluation samples, the layered framework reduced the overall attack success rate from 71.4 percent down to 11.3 percent, measured against unprotected baselines across the three tested models. The authors reported that this performance outperformed their strongest single-layer baseline by 27.3 percentage points and exceeded an existing published guardrail system by 23.8 percentage points.5 In response to questions from Primary, Ahmed identified that external benchmark as NeMo Guardrails, which reached an attack success rate of 35.1 percent under the same test configuration, matching the 23.8 percentage-point separation reported in the preprint.
The framework maintained a false positive rate of 4.8 percent across the test suite, while adding a median latency overhead of 61.2 milliseconds per request. Explaining the latency measurements, Ahmed said the 61.2 millisecond number represents the overall median delay across the entire framework, driven primarily by the semantic encoding calculations in the first and third layers, with a 95th-percentile overhead measured at 97.4 milliseconds. Ablation experiments indicated that each individual layer provided complementary protection and that their combined defense exceeded the sum of their individual contributions.5
What are the boundaries of these findings?
The evaluation reflects benchmark simulations across three specific language models rather than an exhaustive proof against every conceivable evasion technique. The authors conducted their tests on a set of 5,080 structured samples, and the findings have been posted to a preprint server without formal peer review. While the framework restricted attack success to 11.3 percent, it did not eliminate intrusions entirely, leaving a residual risk that attackers could exploit through novel obfuscations or cross-modal vectors.4 The continuous audit loop also assumes that operators actively retrain classifiers as attack strategies evolve over time.5
Discussing these residual failures, Ahmed told Primary that the most consistent bypasses involved novel phrasing expressing hostile intent differently from the training data, as well as implicit soft instructions buried in text. Ahmed also noted that future evaluations should test adaptive adversaries who possess complete knowledge of the three defense layers and distribute commands across multiple retrieved documents. Ahmed added that baseline protection is expected to degrade whenever novel attack styles diverge substantially from the classifier training data, which is the primary reason the design incorporates an active audit cycle.
As organizations connect automated assistants to private databases and enterprise APIs, layered validation between retrieval and generation offers a practical path toward reducing prompt injection risks. Future research will need to test how well similar middleware structures hold up against multi-turn manipulation and complex agent workflows.
This piece was prepared from the arXiv preprint and public records together with answers from Nisar Ahmed to seven questions from the Primary news team, completed September 2026.
The record
33 sentences trace to 5 sources and 1 contributor.
- 1 LLM01:2025 Prompt Injection, OWASP LLM 2025 Explained See the source
- 2 LLM Prompt Injection Prevention - OWASP Cheat Sheet Series See the source
- 3 Prompt Injection | OWASP Foundation See the source
- 4 LLM01:2025 Prompt Injection See the source
- 5 A Layered Security Framework Against Prompt Injection in RAG-Based Chatbots Preprint · may not have been peer reviewed See the source
- 6 Contribution — Nisar Ahmed 15 statements added to this article
Other consulted pages1 page
stackhawk.com1 page
huggingface.co1 page
sixhackacademy.com1 page
Article history
-
Published 13 Nov 2026, 14:16Assembled by the Primary desk from 5 sources · 1 contributor · 33 cited sentences
-
Nisar Ahmed, co-author
- Go to the sentence: At the second layer, the system organizes the retrieved context by enforcing a provenance-based instruction hierarchy, ensuring that retrieved reference material cannot override the system instructions set by the system operator.
- Go to the sentence: Ahmed, a co-author of the preprint, said in response to questions from Primary that this stage treats retrieved text as inherently untrusted data regardless of its phrasing.
- Go to the sentence: In Ahmed's words, the mechanism assigns explicit privilege tiers where operator instructions occupy the highest rank, so that even if an excerpt claims to be an administrator message, its original provenance remains unchanged.
- Go to the sentence: Ahmed cautioned that this structural separation does not make the hierarchy absolute on its own, because the final interpretation still depends on the language model, making the subsequent output audit essential.
- Go to the sentence: The researchers found that the interaction between the final two stages provided the strongest safeguard.
- Go to the sentence: Ahmed told Primary that what surprised him most was how the second and third tiers worked together during ablation tests, noting that when hostile material slipped past context constraints, the output auditor still managed to detect and block the downstream effect.
- Go to the sentence: The authors reported that this performance outperformed their strongest single-layer baseline by 27.3 percentage points and exceeded an existing published guardrail system by 23.8 percentage points.
- Go to the sentence: In response to questions from Primary, Ahmed identified that external benchmark as NeMo Guardrails, which reached an attack success rate of 35.1 percent under the same test configuration, matching the 23.8 percentage-point separation reported in the preprint.
- Go to the sentence: The framework maintained a false positive rate of 4.8 percent across the test suite, while adding a median latency overhead of 61.2 milliseconds per request.
- Go to the sentence: Explaining the latency measurements, Ahmed said the 61.2 millisecond number represents the overall median delay across the entire framework, driven primarily by the semantic encoding calculations in the first and third layers, with a 95th-percentile overhead measured at 97.4 milliseconds.
- Go to the sentence: Ablation experiments indicated that each individual layer provided complementary protection and that their combined defense exceeded the sum of their individual contributions.
- Go to the sentence: The continuous audit loop also assumes that operators actively retrain classifiers as attack strategies evolve over time.
- Go to the sentence: Discussing these residual failures, Ahmed told Primary that the most consistent bypasses involved novel phrasing expressing hostile intent differently from the training data, as well as implicit soft instructions buried in text.
- Go to the sentence: Ahmed also noted that future evaluations should test adaptive adversaries who possess complete knowledge of the three defense layers and distribute commands across multiple retrieved documents.
- Go to the sentence: Ahmed added that baseline protection is expected to degrade whenever novel attack styles diverge substantially from the classifier training data, which is the primary reason the design incorporates an active audit cycle.
