Skip to main content

Prerequisites

In :
  1. If you haven’t already, create an account.
  2. Get your API key.
In Snowsight:
  1. Install the app.
  2. Enter your API key in the app.
  3. If you want to parse documents staged in Snowflake, grant the app access to the stages that have the files you want to parse.

Parse

To parse documents, use the api.parse user-defined function (UDF). The files you specify will be sent to the -hosted service, and the results will display directly in Snowsight. The api.parse function reads a document from a Snowflake stage or publicly accessible URL and returns a structured VARIANT object containing the parsed content. Using the api.parse function is the same as calling the endpoint. For full details about this endpoint and its response, go to .

Sample Scenarios

This section provides examples of how to run the api.parse function in different scenarios.

Parse a File at a Publicly Accessible URL

Run the command below to parse a single file at a publicly accessible URL. We’ve provided a sample file to help you get started. Replace this placeholder with your information: APP_NAME.
USE "APP_NAME";

SELECT
    api.parse(
        'https://va.landing.ai/pdfs/invoice_1.pdf'
    );

Parse a Staged File

Run the command below to parse a single file in a Snowflake stage. Replace these placeholders with your information: APP_NAME, your_db, your_schema, your_stage, and path/to/file.pdf.
USE "APP_NAME";
SELECT
    api.parse(
        '@your_db.your_schema.your_stage/path/to/file.pdf'
    );

Sample Script: Parse a Staged File

Let’s say you have the following setup:
  • APP_NAME: AGENTIC_DOCUMENT_EXTRACTION__APP
  • Database: DEMO_DB
  • Schema: DEMO_SCHEMA
  • Stage: DEMO_STAGE
  • PDF: statement-jane-harper.pdf
You would run the following script to process the PDF:
USE "AGENTIC_DOCUMENT_EXTRACTION__APP";
SELECT
    api.parse(
        '@DEMO_DB.DEMO_SCHEMA.DEMO_STAGE/statement-jane-harper.pdf'
    )

Parse a Batch of Files in a Table

One way to process multiple documents is to create a table that lists the filenames of documents stored in a Snowflake stage. Then, write a SQL script that processes each file by using the file paths from the table. This approach uses the concatenation operator (||) to connect the file paths in your table to the actual documents in your stage. Use the following script to process multiple files from a table. Replace these placeholders with your information: APP_NAME, your_db, your_schema, your_stage, and documents. The script assumes you have a table called documents with a file_path column that lists document filenames.
USE "APP_NAME";

SELECT  
    documents.file_path,
    api.parse(
        '@your_db.your_schema.your_stage/' || documents.file_path
    ) AS parsed_result
FROM your_db.your_schema.documents
WHERE documents.file_path IS NOT NULL;

Sample Script: Parse a Batch of Files in a Table

Let’s say you have the following setup:
  • APP_NAME: AGENTIC_DOCUMENT_EXTRACTION__APP
  • Database: DEMO_DB
  • Schema: DEMO_SCHEMA
  • Stage: DEMO_STAGE (contains PDFs and images)
  • Table: STATEMENTS
The STATEMENTS table has a column called file_path. The file_path column contains the following filenames:
  • statement-george-mathew.png
  • statement-jane-harper.pdf
  • statement-john-doe.png
  • statement-john-smith.png
You would run the following script to process the documents in the STATEMENTS table:
USE "AGENTIC_DOCUMENT_EXTRACTION__APP";

SELECT  
    STATEMENTS.file_path,
    api.parse(
        '@DEMO_DB.DEMO_SCHEMA.DEMO_STAGE/' || STATEMENTS.file_path
    ) AS parsed_result
FROM DEMO_DB.DEMO_SCHEMA.STATEMENTS
WHERE STATEMENTS.file_path IS NOT NULL;
The screenshot below shows a Snowsight worksheet that parsed files listed in a table. Cloud Processing for a Table