Snowflake

Snowflake Document AI: Extract Data from Unstructured Documents

2026-03-26
更新: 2026-03-27
NicheeLab Editorial Team

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.

Document AI Architecture

ドキュメント(PDF/画像)
  → Stage(Internal or External)に格納
    → BUILD_SCOPED_FILE_URL() でファイル参照
      → Document AI モデル(PREDICT関数で推論)
        → VARIANT型の抽出結果
          → FLATTEN + SELECTで構造化テーブルに格納

Document 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.

Creating a Document AI Model

-- Document AIモデルの作成(Snowsight UIで作成するのが推奨)
-- 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.

Example Field Definitions

Field nameWhat it capturesData type
invoice_numberInvoice numberVARCHAR
invoice_dateInvoice dateDATE
total_amountTotal amountNUMBER
vendor_nameVendor nameVARCHAR
line_itemsLine items (multiple)ARRAY

File Reference Functions

-- BUILD_SCOPED_FILE_URL: セッションスコープの一時URL
-- Document AIのPREDICT関数への入力として最も一般的
SELECT BUILD_SCOPED_FILE_URL(
  @invoice_stage,
  'invoices/2026/INV-001.pdf'
) AS scoped_url;

-- BUILD_STAGE_FILE_URL: ステージ参照URL
SELECT BUILD_STAGE_FILE_URL(
  @invoice_stage,
  'invoices/2026/INV-001.pdf'
) AS stage_url;

-- GET_PRESIGNED_URL: 署名付きURL(外部共有用)
SELECT GET_PRESIGNED_URL(
  @invoice_stage,
  'invoices/2026/INV-001.pdf',
  3600  -- 有効期限: 秒
) AS presigned_url;

Comparing File Reference Functions

FunctionUse caseValidity scope
BUILD_SCOPED_FILE_URLSnowflake-internal processing (Document AI, UDFs, etc.)Within the session
BUILD_STAGE_FILE_URLSnowflake-internal referencesValid as long as you hold stage privileges
GET_PRESIGNED_URLTemporary sharing with external applicationsUntil the expiration you specify

Inference with the PREDICT Function

-- 単一ドキュメントの推論
SELECT invoice_extractor!PREDICT(
  BUILD_SCOPED_FILE_URL(@invoice_stage, 'invoices/INV-001.pdf')
) AS 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 Processing Pipeline

-- 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
  );

Extracting Line Items (Array Data)

-- 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;

Using Confidence Scores

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.

-- 信頼度の低い抽出結果をレビューキューに投入
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;

Required Privileges

OperationRequired privileges
Creating a modelCREATE SNOWFLAKE.ML.DOCUMENT_INTELLIGENCE on the database
Running PREDICTUSAGE on the model plus READ on the stage
BUILD_SCOPED_FILE_URLREAD on the stage

Best Practices

  • Validate accuracy on sample documents before batch processing: run 5-10 test inferences to verify accuracy and cost, then move on to the production batch
  • Set a confidence threshold and build a human-review workflow: for example, auto-approve anything at 0.85 or above and route the rest to a review queue
  • Use Directory Tables and Streams for arrival-driven processing: build a pipeline that auto-detects new documents, runs PREDICT, and stores the results in your extracted-data table
  • Keep the raw VARIANT result and structure it later: model updates can change the set of extracted fields, so retain the raw VARIANT in addition to the parsed columns

Check Your Understanding

Cortex AI

問題 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?

  1. GET_PRESIGNED_URL(@stage, path, 3600)
  2. BUILD_SCOPED_FILE_URL(@stage, path)
  3. STAGE_FILE_URL(@stage, path)
  4. READ_FILE(@stage, path)

正解: 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).

Frequently Asked Questions

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.

Check what you learned with practice questions

Practice with certification-focused question sets

無料で問題を解いてみる
Author

NicheeLab Editorial Team

NicheeLab editorial team focused on data engineering and cloud certification learning. Content is structured around practical study needs and official exam domains.


Related articles
Snowflake

Snowflake Certifications: All 11 Exams Explained (2026)

Every SnowPro certification — Associate, Core, Specialty, Ad...

Snowflake

Snowflake Exam Difficulty Ranking: All 11 Certs Compared (2026)

All 11 SnowPro exams ranked by difficulty with study-time es...

Snowflake

Snowflake Study Guide: Fastest Pass Route by Exam (2026)

How to pass SnowPro certifications efficiently — official ma...

Snowflake

SnowPro Core (COF-C03): Complete Exam Guide (2026)

Pass the SnowPro Core exam — six domains, scope, sample ques...

Snowflake

SnowPro Associate Platform (SOL-C01): Complete Guide (2026)

The entry-level SnowPro Associate exam — scope, weighting, s...

Browse all Snowflake articles (103)
© 2026 NicheeLab All rights reserved.