Skip to main content

Overview

When you run the API, the response includes an extraction_metadata field that contains reference IDs linking each extracted field back to specific chunks in the response. These reference IDs allow you to pinpoint the exact document location where each piece of data was found. This workflow requires both and responses:
  • The response contains the grounding information (page numbers and bounding box coordinates)
  • The response contains the extracted data and reference IDs that connect back to those locations
This is useful for visual validation, quality assurance, or building confidence scores.

Scenario and Materials

  • Parse this PDF: Pay Stub
  • Extract these fields: Employee Name and Gross Pay

Scripts

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.
from pathlib import Path
from landingai_ade import LandingAIADE
from landingai_ade.lib import pydantic_to_json_schema
from pydantic import BaseModel, Field

# Define extraction schema
class PayStubData(BaseModel):
    employee_name: str = Field(description="The employee's full name")
    gross_pay: float = Field(description="The gross pay amount")

# Initialize client (uses the API key from the VISION_AGENT_API_KEY environment variable)
client = LandingAIADE()

# Parse the document
parse_response = client.parse(
    document=Path("/path/to/pay-stub.pdf"),
    model="dpt-2-latest"
)

# Extract data
schema = pydantic_to_json_schema(PayStubData)
extract_response = client.extract(
    schema=schema,
    markdown=parse_response.markdown,
    model="extract-latest"
)

# Link extracted field to its source location
chunk_id = extract_response.extraction_metadata["employee_name"]["references"][0]
grounding = parse_response.grounding[chunk_id]

print(f"Employee name: {extract_response.extraction['employee_name']}")
print(f"Found on page {grounding.page}")
print(f"Location: ({grounding.box.left:.3f}, {grounding.box.top:.3f}, {grounding.box.right:.3f}, {grounding.box.bottom:.3f})")
print(f"Chunk type: {grounding.type}")