Detecting PII in Files, PDFs, and Images Uploaded to LLMs
A file-level PII detection pipeline identifies the true file type, extracts content from every layer (native text, OCR output from page and embedded images, metadata, and attachments), runs layered entity detection, and applies a policy action such as block, redact, mask, or route before the content reaches a model, tool, or third-party API. Enforcement belongs in the request path, and each decision should be logged without storing the raw PII.
File inspection path before the model
Inspection runs as an ordered sequence of stages. Each stage hands its output to the next, and the final decision is recorded before content is forwarded.
- IdentifyDetermine the real file type and unpack containers.
- ExtractPull text, images, metadata, and attachments.
- OCRConvert image content to text where needed.
- DetectFind entities with rules, models, or classifiers.
- DecideBlock, redact, mask, or route by policy.
- RecordLog the decision without raw PII.
Why text-only filters miss file content
A file carries content in several layers: native text, page images, embedded images, metadata, and nested attachments. A filter that inspects only the prompt text, or only the native text of a document, does not see the content held in the other layers.
A file-level pipeline therefore starts by identifying the true file type and unpacking containers, then extracts content from every layer before any entity detection runs.
- Native text from the document itself.
- OCR output from page images and embedded images.
- Metadata.
- Attachments, including nested ones.
Extraction and OCR failure modes
OCR converts image content to text where needed, and both extraction and OCR can fail or degrade. Plan for these cases explicitly rather than letting them pass through uninspected.
- Low-quality input: accuracy should be measured on your own documents, including low-quality scans and screenshots.
- Extraction errors, timeouts, and encrypted files: each needs a defined outcome.
- Latency: inspection time should be measured per stage, with OCR applied selectively.
Comparing detection methods on extracted content
The detect stage runs on the extracted content and finds entities with rules, models, or classifiers. Detection is layered, so these methods can be combined rather than chosen in isolation.
Whichever methods you use, measure precision and recall on your own documents, including low-quality scans and screenshots, rather than relying on results from other content.
Choosing the policy action
After detection, the decide stage applies a policy action to the content before it reaches a model, tool, or third-party API.
- Block: stop the file from proceeding.
- Redact: remove the detected content.
- Mask: obscure the detected content.
- Route: send the file along a different path.
Policy granularity matters: actions should differ by entity type, file type, identity, and destination.
Where to enforce and what to log
Enforcement belongs in the request path, so that inspection and the policy decision happen before content reaches a model, tool, or third-party API.
Each decision should be logged without storing the raw PII. Audit records should show the inspection scope and the decisions made.
Evaluation criteria for a file inspection design
Use these criteria to assess whether a file inspection design is complete.
| Criterion | What to verify |
|---|---|
| Coverage | Native text, scanned pages, embedded images, metadata, and nested attachments are all inspected. |
| Accuracy | Precision and recall are measured on your own documents, including low-quality scans and screenshots. |
| Failure handling | Extraction errors, timeouts, and encrypted files have defined outcomes. |
| Policy granularity | Actions differ by entity type, file type, identity, and destination. |
| Latency | Inspection time is measured per stage, with OCR applied selectively. |
| Audit quality | Records show inspection scope and decisions without storing raw PII. |