← Blog

PDF Hidden-Text Prompt Injection Survives the Human Review

Parminder Singh
Parminder Singh··3 min read
Summarize with AI

A PDF can look ordinary on screen while its extracted text contains instructions for an LLM. Secure ingestion preserves provenance, compares visible and extracted content, treats document text as data, and inspects the assembled model request before transmission.

Problem-Awareai-securityprompt-injectionllm-securitydata-loss-preventionpolicy-enforcement
PDF Hidden-Text Prompt Injection Survives the Human Review

A PDF reviewer sees the rendered page. An LLM often receives extracted text instead. White-on-white instructions can survive extraction while remaining absent from the reader's visual check. So can clipped objects, metadata fields, and text placed behind an image. OWASP's 2025 prompt-injection definition explicitly covers inputs that are imperceptible to humans as long as the model parses them.

TL;DR

  • Compare a PDF's rendered page with its extracted text before adding it to model context.
  • Preserve document provenance and mark extracted content as untrusted data inside the assembled prompt.
  • Inspect the complete HTTP model request after parsing and retrieval, once prompt construction is complete.
  • Require separate authorization before a document-processing agent can call a tool.

Rendering and extraction create two documents

PDF is a presentation format with multiple object layers, and a parser may recover text in a reading order that differs from the visible page. OCR produces another representation before a retrieval pipeline chunks that material, where a hidden instruction can become a clean paragraph beside trusted system text.

Open the page, then inspect the extracted text in a second pane. A paragraph that appears only on the right belongs in the security review. Microsoft describes these as document attacks in Prompt Shields, covering hidden instructions in documents and email as well as web pages.

This is a file-specific form of the broader RAG prompt-injection problem. What eventually reaches the model is determined by the parser and chunker.

Secure ingestion preserves provenance

Record the uploader and source system. Preserve the document hash, parser version, extraction method, and each chunk's page and object references as well. Keep OCR text separate from embedded text. Rather than flattening every chunk into anonymous prose, a downstream model request should retain those source labels.

I would reject any ingestion pipeline that cannot show which PDF object produced a disputed sentence. Retrieval quality scores are useful for ranking, but useless during an incident if the original object has vanished.

Scan for large differences between rendered and extracted content. Check suspicious off-canvas coordinates, tiny fonts, invisible colors, and instruction-like language in metadata. Without pretending that one regex solves prompt injection, these signals can trigger quarantine or human review.

Quarantine the file before storing the original PDF and every extracted representation under the same document hash. Keep it out of retrieval until a reviewer resolves the mismatch. The reviewer should see the rendered page beside embedded text, with OCR output in the same view and disputed objects highlighted rather than buried in a parser log.

Prompt assembly must separate instructions and data

The application should place trusted instructions in a privileged channel. Document excerpts belong in a clearly delimited data channel. The StruQ research formalizes this separation and trains a model to follow instructions from the prompt portion rather than the data portion.

Production controls need route policy that classifies the assembled request, restricts the model and tools available to document-processing tasks, caps the amount of retrieved text, and limits the actions permitted for that route. If the PDF asks the agent to reveal a secret or call a tool, the application should treat that text as document content.

Test the assembled request, not only the source file. A harmless-looking chunk can become dangerous when it sits next to a system instruction or receives an authoritative label. Another risk appears when it passes to an agent with tool access. Save the exact prompt structure used for the decision so an investigator can reproduce the route.

Attach page-level provenance to the classifications described in the AI prompt classification taxonomy, so a denied request identifies the exact document segment that triggered the rule.

Response and action controls contain residual risk

Response inspection should flag unexpected secret material, external URLs, tool requests, and instructions that would advance the injected objective. Before any tool call, agents need a separate authorization decision. A PDF summarizer should lack standing authority to send email or modify records, and it should be unable to fetch arbitrary URLs or write files.

Log the document hash with the model request and policy decision. Security teams can then identify every run that consumed a poisoned file and block replay while they replace the source.

DeepInspect

DeepInspect can evaluate the authenticated HTTP request after the application extracts PDF content and assembles the model prompt. Before traffic reaches the LLM, it can apply identity, data-classification, route, and response policies.

PDF parsing, OCR, malware scanning, and storage remain upstream responsibilities. The gateway governs the model-bound representation. It also records the decision tied to the document hash supplied by the application.

Book a demo today.

Frequently asked questions

Does OCR remove hidden-text prompt injection?

OCR changes the extraction path. It can ignore embedded hidden text while still reading visual instructions that a person overlooks. Compare representations, and preserve which extractor produced each chunk.

Can a gateway inspect PDF files directly?

A gateway can inspect content included in the HTTP model request. File parsing and object-level PDF analysis usually happen upstream. To ensure the policy decision reflects the source, send provenance and extracted-text classifications with the routed request.