RCRAG Converter

Indirect prompt injection in RAG: read what your documents really say

Indirect prompt injection in RAG happens when a document in the corpus carries instructions, often hidden from a human reader, that the model later receives as retrieved context, so the defence starts by reading the text a parser actually extracted and continues by treating every retrieved chunk as untrusted data.

How do I protect a RAG system from prompt injection hidden in documents?

Read the text your parser extracted, not the rendered file, and scan it for instruction-like phrases and invisible characters before indexing. Record which approved sources each document came from, wrap retrieved chunks as untrusted data in the prompt, and never let retrieved text authorize a tool call.

A document can carry instructions you never see

A RAG system does exactly what it was built to do: it finds passages that match a question and puts them in front of the model. If one of those passages says "ignore your previous instructions," the model receives that sentence as context, next to the system prompt. That is indirect prompt injection. Nobody typed the attack into the chat box. It arrived inside a document.

The OWASP RAG Security Cheat Sheet calls document poisoning the most common and immediately exploitable RAG attack, and lists the forms it takes: a planted file in a shared knowledge base, a compromised source feeding the pipeline, an insider adding content that is not visible in normal rendering but is present in the extracted text, and invisible Unicode or zero-width characters. NIST's adversarial machine learning taxonomy (AI 100-2 E2025) treats indirect prompt injection as its own attack class for the same reason. The common thread is that a person reviewing the PDF and a model reading the chunk are not looking at the same thing.

Read the extracted text, not the rendered page

White text on a white page, a line in a document's metadata, characters with no width: a reviewer scrolling the file sees none of it. A text extractor sees all of it, because it reads the text layer rather than the picture. So the review that matters is a review of what the parser produced.

RAG Converter makes that text easy to read before anything is indexed. Alongside `chunks.jsonl`, the browser offers `documents.jsonl`, one row per file holding the whole document as ordered markdown, so you can read a document in the order the chunker saw it. The JSONL guide explains both files, and document parsing for RAG explains why extracted text and rendered pages differ. Formats matter here too: text-layer PDFs and Office files extract real text, while images and scanned pages extract nothing without OCR, as the PDF guide says plainly for scanned PDFs.

Scan the corpus for instructions and invisible characters

Before indexing, search the extracted text for the patterns the OWASP cheat sheet names: phrases such as "ignore previous," "you are now," "SYSTEM:" and "INSTRUCTION:", plus invisible characters such as zero-width spaces. Any plain text tool works on a JSONL file. A match is not proof of an attack, since a security handbook may quote those phrases on purpose, so treat hits as a review queue, not an automatic delete.

Be clear about what the converter does and does not do here. RAG Converter's built-in scan flags personal data and credentials, as described in scanning a RAG corpus for personal data. It does not detect prompt injection. That check is yours to add, and the extracted text is what you add it to.

Know where every document came from

Most poisoned documents get in through an ordinary door: a shared drive anyone can write to, a folder synced from a vendor, a bulk upload nobody reviewed. OWASP's first recommendations are about that door. Keep an allowlist of approved sources, record who added each document and when, and store a SHA-256 digest of each approved file in a manifest that the people who can edit documents cannot also edit. A matching digest proves the file is the one you approved, not that it is safe, so the digest and the content review work together.

Converting locally keeps that provenance simple. In the free tier, conversion runs in the visitor's browser tab as WebAssembly, and the bytes do not leave the device. Browser conversion is a Preview capability, so check its current status on the site before relying on it for a production pipeline. The case for keeping files local is in why convert documents locally.

Treat retrieved chunks as data at answer time

Ingestion checks reduce the risk. They do not remove it, because a clever instruction can survive any scan. The last layer is how the application uses what it retrieves. OWASP recommends wrapping retrieved content in clear delimiters that the model is told to treat as data, restating the system instructions after the retrieved block, and limiting how many chunks and tokens retrieval can add. The OWASP LLM Prompt Injection Prevention Cheat Sheet covers hidden text in documents and least privilege for agents in more depth.

The most important rule is about actions. Retrieved text should never be able to approve a payment, send an email or call a tool on its own. If an assistant can act, a human or a fixed policy should approve the action, not a sentence that happened to rank well for the query.

Start with one folder

Pick a folder that more than one person can write to, convert it at the converter, download `documents.jsonl`, and read the extracted text of the files you know least. Search it for instruction phrases and invisible characters, and note where each file came from. That hour tells you more about your exposure than any checklist. The parsing stack comes from Remade with Rust, the memory-safe libraries behind the converter. If you also want the files themselves to stay on hardware you own, MATA's Digital Freedom roadmap is that context, not a claim that it reviews your corpus for you.

More on converting for RAG