snowflake.snowpark.functions.ai_parse_document¶
- snowflake.snowpark.functions.ai_parse_document(file: Column, return_error_details: Optional[bool] = None, **kwargs) Column[source]¶
Returns the extracted content from a document as a JSON-formatted string. This function supports two types of extraction: Optical Character Recognition (OCR), and layout.
- Parameters:
file – A FILE type column containing the document to parse. The document must be on a Snowflake stage that uses server-side encryption and is accessible to the user.
return_error_details – When
True, returns an OBJECT withvalue,error, andmetadatafields.metadatacontains document-level metadata such as page count that is otherwise not surfaced.**kwargs –
Configuration settings specified as key/value pairs. Supported keys:
- mode: Specifies the parsing mode. Supported modes are:
’OCR’: The function extracts text only. This is the default mode.
’LAYOUT’: The function extracts layout as well as text, including structural content such as tables.
extract_images: If set to True, the function extracts images embedded in the document. Requires
mode='LAYOUT'. Each extracted image is returned in theimagesarray with fieldsid, bounding-box coordinates, andimage_base64.page_split: If set to True, the function splits the document into pages and processes each page separately. This feature supports only PDF, PowerPoint (.pptx), and Word (.docx) documents. Documents in other formats return an error. The default is False. Tip: To process long documents that exceed the token limit, set this option to True.
page_filter: An array of page-range objects specifying which pages of a multi-page document to process. Each object must have
start(inclusive, 0-based) andend(exclusive) fields. For example,[{'start': 0, 'end': 2}]processes the first two pages. Specifyingpage_filterimpliespage_split.
- Returns:
A JSON object (as a string) that contains the extracted data and associated metadata. The options argument determines the structure of the returned object.
- If
page_splitis set (orpage_filteris provided), the output contains: pages: An array of JSON objects, each containing text extracted from the document.
- If
page_splitis False or not present, the output contains: content: Plain text (in OCR mode) or Markdown-formatted text (in LAYOUT mode).
- If
extract_imagesis True (requiresmode='LAYOUT'), the output additionally contains: images: An array of objects, each with
id,top_left_x,top_left_y,bottom_right_x,bottom_right_y, andimage_base64fields.
- If
Examples: