PDF Redaction
Agent Mask extracts text from PDFs, including scanned PDFs via OCR, detects configured PII entities, and can return a redacted PDF from a single mask() call.
Quick example
Section titled “Quick example”-- Input must be base64-encoded, zlib-compressed PDF bytes.-- In Snowpark Python:-- stream = session.file.get_stream('@stage/doc.pdf')-- encoded = base64.b64encode(zlib.compress(stream.read())).decode()SELECT app_public.mask( '<compressed_base64_pdf>', OBJECT_CONSTRUCT( 'include_redacted_document', TRUE, 'pdf_mode', 'redact' ));The response columns[0].redacted_document contains the base64-encoded, zlib-compressed redacted PDF.
pdf_mode
Section titled “pdf_mode”"redact" (default)
Section titled “"redact" (default)”Black out detected PII with an opaque fill. Use this mode when you need a redacted visual copy of the PDF. Review the output before external sharing, regulated disclosure, or public release.
"annotate"
Section titled “"annotate"”Highlight detected PII in place with a translucent color overlay. Values remain readable, so this mode is best for controlled review, QA, and tuning detection rules.
OBJECT_CONSTRUCT('pdf_mode', 'annotate')Searchable text layer
Section titled “Searchable text layer”By default, redacted PDFs do not include a searchable text layer. Enable it when you want an OCR sandwich PDF with invisible placeholder text in place of detected PII.
Enable with:
OBJECT_CONSTRUCT( 'include_redacted_document', TRUE, 'include_searchable_text_layer', TRUE)Redaction colors
Section titled “Redaction colors”Customize the redaction fill and text overlay colors:
OBJECT_CONSTRUCT( 'include_redacted_document', TRUE, 'redaction_fill_color', ARRAY_CONSTRUCT(0, 0, 0), -- black fill (default) 'redaction_text_color', ARRAY_CONSTRUCT(255, 255, 255) -- white text overlay (default))RGB tuples, each component 0–255.
Structured extraction
Section titled “Structured extraction”For PDFs with complex layouts (tables, multi-column, headers/footers), use structured extraction to help preserve document structure:
OBJECT_CONSTRUCT( 'document_extraction_mode', 'structured', 'structured_output_format', 'markdown')structured_output_format options: "markdown" (default), "html", "text", "json".
Redaction metadata
Section titled “Redaction metadata”Get per-redaction bounding boxes and page numbers for downstream review:
OBJECT_CONSTRUCT( 'include_redacted_document', TRUE, 'include_redaction_metadata', TRUE)The response gains a redaction_metadata object with an entities_redacted count and pixel bounding_boxes. Each box includes coordinates and a zero-based page.
Review and limitations
Section titled “Review and limitations”PDF redaction applies to entities Agent Mask detects from extracted text and OCR output. Detection quality depends on the PDF layout, scan quality, language, handwriting, entity coverage, and any custom entities you configure.
Treat the returned PDF and metadata as reviewable redaction output, not as proof that every possible identifier has been removed. For external sharing, regulated disclosure, or public release, review representative documents and use redaction_metadata, analyzer results, and your own QA process to confirm the output is appropriate for the workflow.
Scanned PDFs (OCR)
Section titled “Scanned PDFs (OCR)”Scanned PDFs are automatically routed through OCR. No configuration is required; pass the PDF bytes. OCR adds processing time proportional to page count.