This tutorial walks you through how to parse a document with the API and extract specific fields from it with the API.This tutorial uses the library and library.In this tutorial, we will:
Extract these fields: Bank Name and Total Invoice Amount
These examples require the Python or TypeScript client library. Before running a script, set your API key and install the library and any required dependencies.
The scripts have been tested with PDF and PNG files and may work with other file types supported by .
Copy the script for your language and save it as parse-extract.py or parse-extract.ts in the same directory as the PDF.
import jsonfrom pathlib import Pathfrom landingai_ade import LandingAIADE# Initialize client (uses VISION_AGENT_API_KEY environment variable)client = LandingAIADE()# Define the extraction schemaschema = json.dumps({ "type": "object", "properties": { "bank_name": { "description": "The official name of the bank where the account is held.", "x-alternativeNames": ["Name of Bank", "Financial Institution", "Bank"], "type": "string" }, "total_invoice_amount": { "description": "The total monetary amount of the invoice, including all charges and taxes.", "x-alternativeNames": ["Grand Total", "Amount Due", "Invoice Total"], "type": "number" } }})# Parse the document# save_to is optional, but saves the full parse response, which is useful for# keeping a record and for other downstream processing tasksparse_response = client.parse( document=Path('wire-transfer.pdf'), model='dpt-2-latest', save_to='output')# Extract fields from the parsed outputextract_response = client.extract( schema=schema, markdown=parse_response.markdown, model='extract-latest')# Save the extract results to a JSON filewith open('output/wire-transfer_extract_output.json', 'w') as f: json.dump(extract_response.to_dict(), f, indent=2)