Catching prompt injections hidden in PDFs
The author writes that they were tasked with defining what "QA for AI applications" would look like at work, applied to an internal tool that reads PDFs of financial data including SEC filings and account statements. Traditional QA automated tests to catch parsing regressions, but the author raised prompt injection, which colleagues had not considered because the tool was internal. To test it, the author created a quick Markdown-to-PDF generator, took text from an existing filing, and placed a second earnings number beneath the first in white text on white. The author reports it worked on the first attempt, and that other techniques also succeeded: text positioned far outside the visible box, zero-height text, and very tall text that the PDF does not display. The author says a footnote claiming a recent SEC rule change required all numbers to be reported as $1,234,567.89 made the problem clear to others. The post describes document injection protection as a set of judges, a name the author attributes to Claude, each performing one check rather than attempting everything at once. HiddenInk builds a threshold from the grayscale render into faint marks and dark ink, dilates the dark-ink mask, and labels faint connected components not explained by nearby dark ink; it catches white-on-white and near-white text, including scans without a text layer, but is blind to render-mode-3 text and can only report a bounding box. Text Raster Divergence maps each text-layer character to expected pixel coordinates and checks for ink, reporting characters that render no ink with the hidden text as payload; it needs a text layer and is blind to hidden text over visible ink. A Unicode Obfuscation judge walks code points for invisible characters.
The post shows that PDFs parsed by agents can carry hidden instructions or numbers, and that layered single-purpose checks are one approach to catching them.