Parsing documents with AI_PARSE_DOCUMENT¶
AI_PARSE_DOCUMENT is a Cortex AI Function that extracts text, data, layout elements, and images from documents. It can be used with other functions to create custom document processing pipelines for a variety of use cases (see Cortex AI Functions: Documents).
For information on using AI_PARSE_DOCUMENT to extract images, with examples, see Cortex AI Functions: Image extraction with AI_PARSE_DOCUMENT.
The function extracts text and layout from documents stored on internal or external stages and preserves reading order and structures like tables and headers. For information about creating a stage suitable for storing documents, see Create stage for media files.
AI_PARSE_DOCUMENT orchestrates advanced AI models for document understanding and layout analysis and processes complex multi-page documents with high fidelity.
The AI_PARSE_DOCUMENT function offers two modes for processing PDF documents:
LAYOUT mode is the preferred choice for most use cases, especially for complex documents. It’s specifically optimized for extracting text and layout elements like tables, making it the best option for building knowledge bases, optimizing retrieval systems, and enhancing AI based applications.
OCR mode is recommended for quick, high-quality text extraction from documents such as manuals, agreements or contracts, product detail pages, insurance policies and claims, and SharePoint documents.
For both modes, use the page_split option to split multi-page documents into separate
pages in the response. You can also use the page_filter option to process only specified pages.
If using page_filter, page_split is implied, and you do not need to set it explicitly.
AI_PARSE_DOCUMENT is horizontally scalable, enabling efficient batch processing of multiple documents simultaneously. Documents can be processed directly from object storage to avoid unnecessary data movement.
Note
AI_PARSE_DOCUMENT is currently incompatible with custom network policies.
Examples¶
Simple layout example¶
This example uses AI_PARSE_DOCUMENT’s LAYOUT mode to process a two-column research paper. The page_split parameter
is set to TRUE in order to separate the document into pages in the response. AI_PARSE_DOCUMENT returns the content in Markdown
format. The following shows rendered Markdown for one of the processed pages (page index 4 in the JSON output) next to
the original page. The raw Markdown is shown in the JSON response following the images.
Tip
To view either of the these images at a more legible size, select it by clicking or tapping.
The following is the SQL command to process the original document:
The response from AI_PARSE_DOCUMENT is a JSON object containing metadata and text from the pages of the document, like the following. Some page objects have been omitted for brevity.
Table structure extraction example¶
This example demonstrates extracting structural layout, including a table, from a 10-K filing. The following shows the rendered results for one of the processed pages (page index 28 in the JSON output).
Tip
To view either of the these images at a more legible size, select it by clicking or tapping.
The following is the SQL command to process the original document:
The response from AI_PARSE_DOCUMENT is a JSON object containing metadata and text from the pages of the document, like the following. The results for all but the page previously shown have been omitted for brevity.
Slide deck example¶
This example demonstrates extracting structural layout from a presentation. Below we show the rendered results for one of the processed slides (page index 17 in the JSON output).
Tip
To view either of the these images at a more legible size, select it by clicking or tapping.
The following is the SQL command to process the original document:
The response from AI_PARSE_DOCUMENT is a JSON object containing metadata and the text from the slides of the presentation, like the following. The results for some slides have been omitted for brevity.
Multilingual document example¶
This example showcases AI_PARSE_DOCUMENT’s multilingual capabilities by extracting structural layout from a German article. AI_PARSE_DOCUMENT preserves the reading order of the main text even when images and pull quotes are present.
Tip
To view either of the these images at a more legible size, select it by clicking or tapping.
The following is the SQL command to process the original document. Since the document has a single page, you do not need page splitting for this example.
The response from AI_PARSE_DOCUMENT is a JSON object containing metadata and the text from the document, like the following.
Snowflake Cortex can produce a translation to any supported language (English, language code 'en', in this case) as follows:
The translation is as follows:
Using OCR mode¶
OCR mode extracts text from scanned documents, such as screenshots or PDFs containing images of text. It does not preserve layout.
Output:
Process only certain pages of a document¶
This example demonstrates using the page_filter option to extract specific pages from a document, specifically
the first page of a 55-page research paper. Keep in mind that page indexes starts at 0 and ranges are inclusive of
the start value but exclusive of the end value. For example, start: 0, end: 1 returns only the first page (index 0).
Result:
Classify multiple documents¶
To classify multiple documents, first create a table of the files by retrieving the document locations from a directory, converting these locations to FILE objects.
Then apply AI_PARSE_DOCUMENT to each document in the table and process the results, for example by passing them to AI_CLASSIFY to categorize the documents by type. This is an efficient approach to batch document analysis in a document collection.
The query returns classification labels for each document.
Input requirements¶
AI_PARSE_DOCUMENT is optimized for documents both digital-born and scanned. The following table lists the limitations and requirements of input documents:
Maximum file size |
100 MB |
|---|---|
Maximum pages per document |
500 |
Maximum page resolution |
|
Supported file type |
PDF, PPTX, DOCX, JPEG, JPG, PNG, TIFF, TIF, HTML, TXT |
Stage encryption |
Server-side encryption |
Font size |
8 points or larger for best results |
Supported document features and limitations¶
Page orientation |
AI_PARSE_DOCUMENT automatically detects page orientation. |
|---|---|
Page splitting |
AI_PARSE_DOCUMENT can split multi-page documents into individual pages and parse each separately. This is useful for processing large documents that exceed the maximum size. |
Page filtering |
AI_PARSE_DOCUMENT can process some of the pages in a document, instead of all of them, by specifying page ranges. This is useful when you know what pages the information you’re looking for is on. |
Characters |
AI_PARSE_DOCUMENT detects the following characters:
|
Images |
AI_PARSE_DOCUMENT generates markup for images in the document, but does not currently extract the actual images. |
Structured elements |
AI_PARSE_DOCUMENT automatically detects and extracts tables and forms. |
Fonts |
AI_PARSE_DOCUMENT recognizes text in most serif and sans-serif fonts, but may have difficulty with decorative or script fonts. The function does not recognize handwriting. |
Supported languages¶
AI_PARSE_DOCUMENT is trained for the following languages:
OCR Mode |
LAYOUT Mode |
|---|---|
|
|
Regional availability¶
Support for AI_PARSE_DOCUMENT is available to accounts in the following Snowflake regions:
AWS |
Azure |
Google Cloud Platform |
|---|---|---|
US West 2 (Oregon) |
East US 2 (Virginia) |
US Central 1 (Iowa) |
US East (Ohio) |
West US 2 (Washington) |
|
US East 1 (N. Virginia) |
Europe (Netherlands) |
|
Europe (Ireland) |
||
Europe Central 1 (Frankfurt) |
||
Asia Pacific (Sydney) |
||
Asia Pacific (Tokyo) |
AI_PARSE_DOCUMENT has cross-region support in other Snowflake regions. For information on enabling Cortex AI cross-region support, see Cross-region inference.
Access control requirements¶
To use the AI_PARSE_DOCUMENT function, a user with the ACCOUNTADMIN role must grant the SNOWFLAKE.CORTEX_USER database role to the user who will call the function. See Cortex LLM privileges topic for details.
Cost considerations¶
The Cortex AI_PARSE_DOCUMENT function incurs compute costs based on the number of pages per document processed. The following describes how pages are counted for different file formats:
For paged file formats (PDF, DOCX), each page in the document is billed as a page.
For image file formats (JPEG, JPG, TIF, TIFF, PNG), each individual image file is billed as a page.
For HTML and TXT files, each chunk of 3,000 characters is billed as a page, including the last chunk, which may be less than 3,000 characters.
Snowflake recommends executing queries that call the Cortex AI_PARSE_DOCUMENT function in a smaller warehouse (no larger than MEDIUM). Larger warehouses do not increase performance.
Error conditions¶
Snowflake Cortex AI_PARSE_DOCUMENT can produce the following error messages:
Message |
Explanation |
|---|---|
|
Input document contains unsupported language. |
|
The document is in unsupported format. |
|
The file format is not supported and understood as a binary file. |
|
The document exceeds the 500-page limit. |
|
Image input or a converted document page is larger than the supported dimensions. |
|
Page is larger than the supported dimensions. |
|
The document is larger than 100 MB. |
|
The file does not exist. |
|
The file can’t be accessed due to insufficient privileges. |
|
Timeout occurred. |
|
System error occurred. Wait and try again. |
Legal notices¶
The data classification of inputs and outputs are as set forth in the following table.
Input data classification |
Output data classification |
Designation |
|---|---|---|
Usage Data |
Customer Data |
Generally available functions are Covered AI Features. Preview functions are Preview AI Features. [1] |
For additional information, refer to Snowflake AI and ML.







