Test LLM guardrails on scanned documents

Measure what your OCR pipeline misses before LLM guardrails inspect the text, and set review rules for uncertain pages.

Test the guardrail on both a verified transcription and the OCR output from the same page. If it detects an identifier in the transcription but misses it in the OCR output, examine what the extractor changed or omitted. A detector score measured on clean text tells you little about pages that produce partial text or no text at all.

Track extraction and screening as separate steps

Start with the document as received. Record the expected page count, the extractor version, extraction status by page, and the representation actually sent for screening. For tables and form fields, retain page and field references in your test output. A detector can find a value correctly while your redaction code masks the wrong occurrence or leaves a second copy in another extracted field.

Amazon Textract recommends evaluating confidence in the context of the use case. Microsoft Document Intelligence distinguishes word-level confidence from field-level predictions, and it documents variation between scanned and digital documents. Use confidence to prioritize review. Test page and field completeness independently because an omitted field may offer no score to evaluate. Amazon Textract best practices and Microsoft Document Intelligence accuracy and confidence

Use a small set that reflects the documents your team accepts. For instance, start with synthetic forms rendered as a digital PDF, rotated scan, faint photocopy and scan with a handwritten annotation. Label the expected sensitive values and the places they occur. Keep the synthetic originals and their reviewed transcriptions so you can use the same inputs when you update the extractor or guardrail.

Assign each failed case to the correct stage

Suppose your internal procurement assistant summarizes invoices after removing bank details. The test policy requires a complete extraction and successful redaction before the application submits text to the model. These hypothetical cases show how to investigate:

Observation Stage to investigate Expected application action
Bank details appear in the transcription but a page is absent from OCR output Extraction coverage Hold the document for review.
The transcription triggers redaction and OCR splits the value into disconnected fields Parsing and field assembly Hold until you can verify the value was removed from the assembled text.
Both versions contain the same value and both pass through unchanged Detector or policy coverage Keep the document out of the model path and review the rule.
The extracted value is removed from the text but survives in a field serialized to the model Request assembly Block the request and fix the code that assembles the payload.

Count missing or unreadable pages in the extraction results. For the guardrail, report findings against the values that reached it, including whether it took the expected action. For the workflow, count how many documents reached inference with prohibited data. You need all three views to tell whether to adjust page handling, detector configuration or the application request builder.

Decide what the workflow can accept

Use the test to define release criteria by input format. For example, accept digital PDFs that have complete text extraction and pass screening, and route scans with missing pages or uncertain required fields to authorized review. Size the review queue before expanding the pilot. A stricter confidence threshold can raise review volume without correcting pages that are consistently omitted. Watch both the proportion routed to review and the miss rate on an independently labelled sample.

If your application can also attach the original PDF or render a page as an image for a model, test that path separately. Redacting extracted text leaves the original file intact. For the request in your pilot, assert precisely which parts can go upstream. For broader format coverage, see what AI guardrails can inspect in attachments. Alectura documents guardrails for supported text inputs and an attachment_uninspectable refusal when the policy blocks content it cannot inspect. Review the guardrail coverage and actions for the fields your application sends.

Source documents (2)

Trace a request through Alectura.

Bring a sample prompt and a customer policy. See what reaches the model and which decisions appear in the request record.

Try the quickstart

Keep reading

Measure LLM abstention before automating routing ↗Set guardrails for LLM spreadsheet exports ↗Cut over to a new embedding model safely ↗