Document AI is a managed Snowflake capability that extracts structured data — text, numbers, dates, and more — from unstructured documents like PDFs and images. It combines pre-trained OCR (Optical Character Recognition) and NER (Named Entity Recognition) models so you can pull required fields from invoices, receipts, contracts, and medical records directly with SQL.
Documents (PDF / images)
-> stored in a Stage (Internal or External)
-> referenced with BUILD_SCOPED_FILE_URL()
-> Document AI model (inference via the PREDICT function)
-> extraction result as VARIANT
-> FLATTEN + SELECT into a structured tableDocument AI runs on Snowflake's Serverless Compute, so you don't have to provision a warehouse yourself. Extraction results come back as a VARIANT value, and you can access individual fields using JSON path notation.
-- Create a Document AI model (creating it in the Snowsight UI is recommended)
-- Example of creating it in SQL
CREATE OR REPLACE SNOWFLAKE.ML.DOCUMENT_INTELLIGENCE
invoice_extractor
FROM @doc_stage
USING (
SELECT
BUILD_SCOPED_FILE_URL(@doc_stage, relative_path) AS file_url
FROM DIRECTORY(@doc_stage)
WHERE relative_path LIKE '%.pdf'
LIMIT 10
);In the Snowsight UI you can visually annotate the fields (Values) you want to extract on the uploaded sample documents, then fine-tune the model from there.
| Field name | What it captures | Data type |
|---|---|---|
| invoice_number | Invoice number | VARCHAR |
| invoice_date | Invoice date | DATE |
| total_amount | Total amount | NUMBER |
| vendor_name | Vendor name | VARCHAR |
| line_items | Line items (multiple) | ARRAY |
-- BUILD_SCOPED_FILE_URL: a session-scoped temporary URL
-- The most common input to the Document AI PREDICT function
SELECT BUILD_SCOPED_FILE_URL(
@invoice_stage,
'invoices/2026/INV-001.pdf'
) AS scoped_url;
-- BUILD_STAGE_FILE_URL: a stage reference URL
SELECT BUILD_STAGE_FILE_URL(
@invoice_stage,
'invoices/2026/INV-001.pdf'
) AS stage_url;
-- GET_PRESIGNED_URL: a pre-signed URL (for sharing externally)
SELECT GET_PRESIGNED_URL(
@invoice_stage,
'invoices/2026/INV-001.pdf',
3600 -- expiry in seconds
) AS presigned_url;| Function | Use case | Validity scope |
|---|---|---|
| BUILD_SCOPED_FILE_URL | Snowflake-internal processing (Document AI, UDFs, etc.) | Within the session |
| BUILD_STAGE_FILE_URL | Snowflake-internal references | Valid as long as you hold stage privileges |
| GET_PRESIGNED_URL | Temporary sharing with external applications | Until the expiration you specify |
-- Inference on a single document
SELECT invoice_extractor!PREDICT(
BUILD_SCOPED_FILE_URL(@invoice_stage, 'invoices/INV-001.pdf')
) AS result;
-- Extract individual fields from the result
SELECT
result:invoice_number::VARCHAR AS invoice_number,
result:invoice_date::DATE AS invoice_date,
result:total_amount::NUMBER(12,2) AS total_amount,
result:vendor_name::VARCHAR AS vendor_name,
result:__confidence::FLOAT AS overall_confidence
FROM (
SELECT invoice_extractor!PREDICT(
BUILD_SCOPED_FILE_URL(@invoice_stage, 'invoices/INV-001.pdf')
) AS result
);-- Batch inference combined with Directory Tables
INSERT INTO extracted_invoices (file_path, invoice_number, invoice_date, total_amount, vendor_name, confidence, extracted_at)
SELECT
d.relative_path,
r.result:invoice_number::VARCHAR,
r.result:invoice_date::DATE,
r.result:total_amount::NUMBER(12,2),
r.result:vendor_name::VARCHAR,
r.result:__confidence::FLOAT,
CURRENT_TIMESTAMP()
FROM DIRECTORY(@invoice_stage) d,
LATERAL (
SELECT invoice_extractor!PREDICT(
BUILD_SCOPED_FILE_URL(@invoice_stage, d.relative_path)
) AS result
) r
WHERE d.relative_path LIKE '%.pdf'
AND d.relative_path NOT IN (
SELECT file_path FROM extracted_invoices
);-- Expand the line items with FLATTEN
SELECT
result:invoice_number::VARCHAR AS invoice_number,
item.value:description::VARCHAR AS item_description,
item.value:quantity::INT AS quantity,
item.value:unit_price::NUMBER(10,2) AS unit_price,
item.value:amount::NUMBER(12,2) AS line_amount
FROM (
SELECT invoice_extractor!PREDICT(
BUILD_SCOPED_FILE_URL(@invoice_stage, 'invoices/INV-001.pdf')
) AS result
),
LATERAL FLATTEN(input => result:line_items) AS item;Each extracted field comes with a confidence score from 0.0 to 1.0. Low-confidence fields need human review, so the production best practice is to set a threshold and route anything below it to a review queue.
-- Send low-confidence extractions to a review queue
INSERT INTO review_queue (file_path, field_name, extracted_value, confidence)
SELECT
relative_path,
'total_amount',
result:total_amount::VARCHAR,
result:total_amount_confidence::FLOAT
FROM extracted_results
WHERE result:total_amount_confidence::FLOAT < 0.85;| Operation | Required privileges |
|---|---|
| Creating a model | CREATE SNOWFLAKE.ML.DOCUMENT_INTELLIGENCE on the database |
| Running PREDICT | USAGE on the model plus READ on the stage |
| BUILD_SCOPED_FILE_URL | READ on the stage |
Cortex AI
Question 1
You want to extract data from PDF files in an Internal Stage using Snowflake Document AI. Which function is the most appropriate to use when passing a file to PREDICT?
Correct answer: B
When passing a file to Document AI's PREDICT function, BUILD_SCOPED_FILE_URL() is the recommended choice. It produces a session-scoped temporary URL optimized for Snowflake-internal processing. GET_PRESIGNED_URL is meant for external sharing and is not appropriate as Document AI input. STAGE_FILE_URL and READ_FILE don't exist as functions (BUILD_STAGE_FILE_URL does exist, but BUILD_SCOPED_FILE_URL is what's recommended for PREDICT input).
Which file formats can Document AI process?
Document AI handles PDF, PNG, JPEG, and TIFF documents. Both scanned paper documents and digital PDFs are supported. Files live in a Snowflake internal or external stage and are referenced via BUILD_SCOPED_FILE_URL() or BUILD_STAGE_FILE_URL(). Check the release notes for the latest per-file size and page-count limits.
Do I need to custom-train the Document AI model?
Common fields (dates, amounts, addresses, names, etc.) can be extracted out of the box with the pre-trained model. For industry-specific formats or proprietary layouts, you can fine-tune the model in Snowsight by providing annotated samples. Annotating just 5-10 sample documents typically delivers a sizable accuracy gain.
How is Document AI billed?
Document AI is billed via Serverless Credits. Cost depends on the page count and complexity of each document, scaling roughly with the total pages processed. For high-volume workloads, the recommended approach is to validate accuracy and cost on a small sample first, then scale up to batch processing once the numbers look right.
Practice with certification-focused question sets
Try free questionsNicheeLab Editorial Team
NicheeLab editorial team focused on data engineering and cloud certification learning. Content is structured around practical study needs and official exam domains.
Snowflake Certifications: All 11 Exams Explained (2026)
Every SnowPro certification — Associate, Core, Specialty, Ad...
Snowflake Exam Difficulty Ranking: All 11 Certs Compared (2026)
All 11 SnowPro exams ranked by difficulty with study-time es...
Snowflake Study Guide: Fastest Pass Route by Exam (2026)
How to pass SnowPro certifications efficiently — official ma...
SnowPro Core (COF-C03): Complete Exam Guide (2026)
Pass the SnowPro Core exam — six domains, scope, sample ques...
SnowPro Associate Platform (SOL-C01): Complete Guide (2026)
The entry-level SnowPro Associate exam — scope, weighting, s...