Skip to content
Guide
Extract
Guides

Configuring Extract

Everything needed to configure an Extract job in one place — core concepts, schema design and restrictions, configuration options, and performance tips.

This page is the map for an Extract job: the concepts a job is built from, how to write the schema that drives it, every option you can set alongside that schema, and the practices that keep extraction accurate as you scale.

For the field-by-field request reference, see the Extract API Reference. For the extra metadata a job can return, see Metadata Extensions.

LlamaExtract is designed to be a flexible and scalable extraction platform. At the core of the platform are the following concepts:

  • Extraction Configurations: Reusable settings including schema, tier, and extraction options.
  • Data Schema: Structured definition for the data you want to extract in JSON/Pydantic format. See detailed explanation below.
  • Extraction Target: Defines the scope of extraction and how your schema is applied to documents. See detailed explanation below.
  • Extraction Jobs: Asynchronous tasks that extract structured data from documents using a configuration.
  • Extraction Runs: The results of an extraction job including the extracted data and other metadata.

The Data Schema defines the structure of the data you want to extract from your documents. It is a JSON Schema that specifies the fields, types, and descriptions for the information you need.

While the schema is fundamentally a JSON Schema (supporting a subset of the full JSON Schema specification), our Python SDK allows you to use Pydantic models for a more Pythonic experience with type validation and IDE support.

Fields, types, size limits, and the JSON Schema subset that Extract accepts are covered in Schema design and restrictions below.

The Extraction Target determines how your schema is applied to the document and what granularity of results you receive. This is an important configuration option as it fundamentally changes how data is extracted.

Extraction Target Visualization

per_doc (Default)per_pageper_table_row
When to UseDefault mode for extracting data from the full document based on your JSON schemaEach page independently contains information about a different entity (e.g., each page contains financial information about a different portfolio company)Document contains an ordered list of entities (in tables, bulleted/numbered lists, or separated by headers) and you want to extract the same information for each entity
How It WorksSchema is applied to the entire document as a single unitSchema is applied independently to each page of the documentSchema is applied to each identified entity in the document. LlamaExtract automatically detects formatting patterns that distinguish entities (table rows, list items, section headers, etc.)
ReturnsA single JSON object matching your schemaAn array of JSON objects, one per page, each matching your schemaAn array of JSON objects, one per entity/row, each matching your schema
Example Use CasesExtracting summary information from a contract, annual report, or research paperMulti-page forms where each page represents a different entity, or a document with one record per page
  • Invoice line items (each row is a product/service)
  • Employee lists or directories
  • Purchase orders with multiple items
  • Any document with repeating structured entities
Important Notes-Your schema should describe a single entity/page, not a list. Don’t use extracted_result: list[template], instead provide the template directly that will be applied at the page level
  • Your schema should describe a single entity, not a list. Don’t use extracted_result: list[template], instead provide the template directly that will be applied at the entity level
  • The document must have some formatting or structure that distinguishes the different entities (table formatting, bullets, numbering, headers, etc.)
  • Entities should appear in an ordered manner in the document

The schema is the most important part of an extraction configuration. It defines the structure of the data you want back, and its field descriptions are what steer the extraction model.

A schema is made of fields. Each field has a name, a type, and optionally a description.

  • Field names — Use clear, stable names that match how you’ll use the data (e.g. invoice_number, vendor_name). These become the keys in the extracted JSON.
  • Field descriptions — Descriptions are additional context for the underlying LLM. They are not only for documentation: the extraction model uses them to decide what to extract. Use descriptions to guide the model on what the value for the field could be—for example, what the field means, where it usually appears in the document, acceptable formats, or examples. Better descriptions typically lead to more accurate and consistent extraction.

LlamaExtract only supports a subset of the JSON Schema specification. While limited, it should be sufficient for a wide variety of use-cases.

  • If you are specifying the schema as a JSON, there are two ways you can mark optional fields:
    • not including them in the containing object’s required array
    • explicilty marking them as nullable fields using anyOf with a null type. See "start_date" field in the example schema.
  • If you are using Pydantic for specifying the schema in the Python SDK, you can use the Optional annotation for marking optional fields.
  • Root node must be of type object.
  • Schema nesting must be limited to within 7 levels.
  • The important fields are key names/titles, type and description. Fields for formatting, default values, etc. are not supported. If you need these, you can add the restrictions to your field description and/or use a post-processing step. e.g. default values can be supported by making a field optional and then setting "null" values from the extraction result to the default value.
  • Additional schema restrictions:
    • Maximum properties: 5,000 total properties across the entire schema.
    • Maximum total string content: 120,000 characters for all strings (field names, descriptions, enum values, etc.) combined.
    • Maximum raw JSON schema size: 150,000 characters for the raw JSON schema string.
  • If you hit these limits for complex extraction use cases, consider restructuring your extraction workflow to fit within these constraints, e.g. by extracting subsets of fields and later merging them together.

The Agentic Plus tier supports schemas up to 3,200 fields, and charges more per page as the schema grows past 200. See pricing for the multipliers. Schema size is also a good proxy for how hard an extraction is, so it’s worth knowing how it’s counted even if you aren’t near the limit.

Size is the number of leaf fields in the schema you submit, meaning the scalar values at the bottom of the tree. It does not depend on the document or on how much data comes back.

  • Objects don’t count themselves, only the leaves inside them. {"address": {"city": ..., "zip": ...}} is 2 fields.
  • Arrays count their item schema once, no matter how many items get extracted. An array of 40 line items with 5 fields each counts as 5 fields, not 200.
  • An array of scalars, e.g. {"tags": ["string"]}, counts as 1 field.
  • $ref is expanded at each place it’s used. If three fields all point at the same 10-field Address definition, that’s 30 fields, not 10. Reusing a definition keeps your schema readable but doesn’t make it smaller.

So a schema with 30 top-level scalars and a table of 10 columns is 40 fields, well under the point where the multiplier starts.

  • Try to limit schema nesting to 3-4 levels.
  • Make fields optional when data might not always be present (specially boolean and int fields where defaults for missing values could cause confusion).
  • When you want to extract a variable number of entities, use an array type. However, note that you cannot use an array type for the root node.
  • Use descriptive field names and detailed descriptions. Use descriptions to pass formatting instructions or few-shot examples.
  • Above all, start simple and iteratively build your schema to incorporate requirements.

Instead of manually defining schemas, you can use LlamaExtract’s automatic schema generation feature. The system can generate a schema based on:

  • A natural language prompt: Describe what data you want to extract
  • A sample file: Upload a document and let the system infer the schema from its structure
  • An existing schema to refine: Provide a base schema and let the system improve or extend it

You can combine these inputs — for example, provide both a sample file and a prompt to guide the generation.

Terminal window
curl -X 'POST' \
'https://api.cloud.llamaindex.ai/api/v2/extract/schema/generate?project_id={PROJECT_ID}' \
-H 'accept: application/json' \
-H "Authorization: Bearer $LLAMA_CLOUD_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"prompt": "Extract invoice details including invoice number, date, vendor name, line items with descriptions and amounts, and total amount",
"file_id": "optional-file-id-for-sample-document"
}'

For the full API documentation, see the LlamaExtract API Reference.

The Python SDK can be installed using

Terminal window
pip install llama-cloud>=2.1

Schemas can be defined using either Pydantic models or JSON Schema:

from pydantic import BaseModel, Field
from typing import List, Optional
class Experience(BaseModel):
company: str = Field(description="Company name")
title: str = Field(description="Job title")
start_date: Optional[str] = Field(description="Start date of employment")
end_date: Optional[str] = Field(description="End date of employment")
class Resume(BaseModel):
name: str = Field(description="Candidate name")
experience: List[Experience] = Field(description="Work history")
schema = Resume.model_json_schema()
schema = {
"type": "object",
"properties": {
"name": {"type": "string", "description": "Candidate name"},
"experience": {
"type": "array",
"description": "Work history",
"items": {
"type": "object",
"properties": {
"company": {
"type": "string",
"description": "Company name",
},
"title": {"type": "string", "description": "Job title"},
"start_date": {
"anyOf": [{"type": "string"}, {"type": "null"}],
"description": "Start date of employment",
},
"end_date": {
"anyOf": [{"type": "string"}, {"type": "null"}],
"description": "End date of employment",
},
},
},
},
},
}

With your schema, you can directly run extractions using the SDK:

from llama_cloud import LlamaCloud
client = LlamaCloud(api_key="your_api_key")
file_obj = client.files.create(file="path/to/your/document.pdf", purpose="extract")
job = client.extract.create(
file_input=file_obj.id,
configuration={
"data_schema": schema,
"tier": "agentic",
},
)
# Poll for completion
while job.status not in ("COMPLETED", "FAILED", "CANCELLED"):
import time; time.sleep(2)
job = client.extract.get(job.id)

The schema decides what comes back. The options below decide how the job runs — which tier interprets the document, which pages it reads, and what extra metadata it returns. The extraction target belongs to this group too; it is described above because it changes the shape of your results, not just their quality.

Extract tiers determine how much effort LlamaExtract puts into producing structured data from a document.

Agentic Plus provides the highest extraction quality across document types, including short or straightforward documents. Use it when you want the best result and can accept higher cost and latency. It may take longer on long or complex documents as it puts more iterative effort into the result. It also supports the largest schemas (up to 3,200 fields); schemas above 200 fields incur a per-page credit multiplier — see pricing.

Agentic balances quality, cost, and latency across a broad range of documents, including mixed layouts and tables.

Cost Effective prioritizes lower cost and latency for straightforward extraction, especially at high volume. It works best when fields and layouts are predictable and ambiguity is limited.

Each extract tier has a default parse tier chosen to balance cost and quality. You can override the parse tier in Advanced Settings when your workload needs lower parsing cost or higher-quality document interpretation. See pricing for the default combinations and additive costs.

All tiers use the same version convention. Use latest while evaluating changes, then pin the resolved date in production. latest selects the newest version compatible with the requested options, while a date selects the newest release for that tier on or before the date.

Under Advanced Settings in the UI you can fine-tune how extraction runs:

  • Parse tier: Select the parsing tier used to interpret the input document before extraction. This uses the same v2 parse tiers as LlamaParse (for example, cost_effective, agentic, and agentic_plus). See Tiers for details.
  • Cite sources: Enable cite sources to attach citations to extracted fields so you can trace every value back to its origin in the document.
  • Confidence scores: Enable confidence scores to get per-field confidence signals alongside extracted output.
  • System prompt: Provide a system prompt to globally guide the extractor (for example, “Prefer the most recent fiscal year if multiple are present”, or “Return numbers as plain numerals without currency symbols”).
  • System Prompt: Any additional system level instructions for the extraction. Note that you should use the schema descriptions to pass field-level instructions, few-shot examples, formatting instructions, etc.
  • Page Range: Specify which pages to extract from by providing comma-separated page numbers or ranges (1-based indexing). For example, use 1,3,5-7,9 to extract pages 1, 3, pages 5 through 7, and page 9. You can also use ranges like 1-3,8-10 to extract the first three pages and pages 8 through 10. Page numbers are 1-based, meaning the first page is page 1. This option is useful when you only need to extract data from specific sections of large documents.

  • Context Window: Number of pages to pass as context for long document extraction. This is useful when extracting from large documents where you need context from surrounding pages. This is configurable via the extraction tier and system prompt. Larger values keep more of the surrounding document intact, which helps when you need to see multi-page tables or invoices in one pass. Smaller values advance through the file more aggressively and are better when you need exhaustive coverage of dense lists.

For additional extraction features that provide enhanced metadata and insights, see the Metadata Extensions page which covers:

  • Citations: Source tracing for extracted fields
  • Confidence Scores: Quantitative confidence measures

These extensions return additional metadata in the extract_metadata field but may impact processing time.

You can configure these options when creating an extraction job using either the REST API or Python SDK.

First, install the Python SDK:

Terminal window
pip install llama-cloud>=2.1

Here’s how to set various configuration options:

import time
from llama_cloud import LlamaCloud, AsyncLlamaCloud
client = LlamaCloud(api_key="your_api_key")
schema = {
"type": "object",
"properties": {
"company_name": {"type": "string", "description": "Name of the company"},
"revenue": {"type": "number", "description": "Annual revenue in USD"}
}
}
file_obj = client.files.create(file="path/to/your/document.pdf", purpose="extract")
file_id = file_obj.id
job = client.extract.create(
file_input=file_id,
configuration={
"data_schema": schema,
"extraction_target": "per_doc", # per_doc, per_page, per_table_row
"tier": "agentic", # cost_effective, agentic, agentic_plus
"version": "2026-03-31", # Pin behavior to the latest release available on this date
"system_prompt": "Focus on the most recent financial data",
"target_pages": "1-5,10-15", # Extract from specific pages
"cite_sources": True, # Enable citations
"confidence_scores": True, # Enable confidence scores
},
)
# Poll for completion
while job.status not in ("COMPLETED", "FAILED", "CANCELLED"):
time.sleep(2)
job = client.extract.get(job.id)

You can configure these options using the REST API when creating an extraction job:

Terminal window
curl -X 'POST' \
'https://api.cloud.llamaindex.ai/api/v2/extract?project_id={PROJECT_ID}' \
-H 'accept: application/json' \
-H "Authorization: Bearer $LLAMA_CLOUD_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"file_input": "{FILE_ID}",
"configuration": {
"data_schema": {
"type": "object",
"properties": {
"company_name": {"type": "string", "description": "Name of the company"},
"revenue": {"type": "number", "description": "Annual revenue in USD"}
}
},
"extraction_target": "per_doc",
"tier": "agentic",
"version": "2026-03-31",
"system_prompt": "Focus on the most recent financial data",
"target_pages": "1-5,10-15",
"cite_sources": true,
"confidence_scores": true
}
}'
OptionTypeDefaultDescription
Schema Alignment
extraction_targetstring”per_doc”Extraction scope: per_doc, per_page, per_table_row. Agentic Plus supports per_doc only.
Tier
tierstring”agentic”Extraction tier: cost_effective, agentic (default), agentic_plus
versionstring”latest”Extract algorithm version. Use “latest” during development or pin to a date in YYYY-MM-DD format for stable production behavior.
System Prompt
system_promptstringnullAdditional system-level instructions
Page Range and Context
target_pagesstringnullComma-separated page numbers or ranges to process (1-based, e.g., “1,3,5-7”). Pages are processed in the order listed, so “3,1,2” feeds page 3 first, then 1, then 2.
max_pagesintegernullMaximum number of pages to process
Metadata Extensions
cite_sourcesbooleanfalseEnable source citations
confidence_scoresbooleanfalseEnable confidence scores

For maximum extraction success:

  1. Start with the agentic tier for debugging: When troubleshooting extraction issues, use the agentic tier which uses the most capable models. If extraction succeeds with agentic, you can try cost_effective to see if quality holds for your use case. If extraction fails even with agentic, the issue is likely in your schema design (e.g., ambiguous field descriptions).

    import time
    from llama_cloud import LlamaCloud
    client = LlamaCloud(api_key="your_api_key")
    schema = {
    "type": "object",
    "properties": {
    "company_name": {"type": "string", "description": "Name of the company"},
    "revenue": {"type": "number", "description": "Annual revenue in USD"},
    },
    }
    file_obj = client.files.create(file="path/to/your/document.pdf", purpose="extract")
    # Start debugging with agentic tier
    job = client.extract.create(
    file_input=file_obj.id,
    configuration={
    "data_schema": schema,
    "extraction_target": "per_doc",
    "tier": "agentic",
    },
    )
    # Poll for completion
    while job.status not in ("COMPLETED", "FAILED", "CANCELLED"):
    time.sleep(2)
    job = client.extract.get(job.id)
    print(job.extract_result)
  2. Start small and iterate: Begin with a subset of your data or schema to validate your extraction approach and iterate on your schema description (e.g. adding examples, formatting instructions etc.) to get better accuracy before scaling.

  3. Design clear, focused schemas: Prefer precise short descriptions over verbose fields that try to do too much. See Schema design and restrictions and Avoid complex field transformations.

  4. Leverage document structure: Use page ranges, extraction targets, sections, and chunking strategies to optimize processing. See Configuration options.

  5. Combine tools strategically: Extract excels at extracting information from documents. Focus on leveraging this strength while using complementary tools for computational tasks and validation (e.g., heavy calculations are better handled in a post-processing step).

The situation: When working with documents containing tables, spreadsheets (CSV/Excel), or ordered lists of entities, you want to ensure comprehensive and accurate extraction of each row or item.

Use per_table_row extraction target: If you are only interested in extracting or transforming data from a table or ordered list of entities, use the per_table_row extraction target. This processes each row individually for comprehensive coverage and accurate results.

# Optimal: Use per_table_row for tabular data extraction
extraction_config = {
"extraction_target": "per_table_row",
}

When your schema has additional elements beyond the table: If your schema includes fields that need to be extracted from outside the table (e.g., document metadata, headers, or summary information), you can run separate extractions for tabular data (using per_table_row) and non-tabular elements.

import time
from llama_cloud import LlamaCloud
client = LlamaCloud(api_key="your_api_key")
metadata_schema = {
"type": "object",
"properties": {
"report_title": {"type": "string", "description": "Title of the report"},
},
}
table_row_schema = {
"type": "object",
"properties": {
"line_item": {"type": "string", "description": "Name of the line item"},
"amount": {"type": "number", "description": "Amount in USD"},
},
}
file_obj = client.files.create(file="path/to/your/document.pdf", purpose="extract")
file_id = file_obj.id
# First extraction: Get document-level metadata
metadata_job = client.extract.create(
file_input=file_id,
configuration={
"data_schema": metadata_schema,
"extraction_target": "per_doc",
"tier": "agentic",
},
)
# Second extraction: Get table row data
table_job = client.extract.create(
file_input=file_id,
configuration={
"data_schema": table_row_schema,
"extraction_target": "per_table_row",
"target_pages": "5-10",
"tier": "agentic",
},
)
# Wait for both jobs and print the results
for job in (metadata_job, table_job):
while job.status not in ("COMPLETED", "FAILED", "CANCELLED"):
time.sleep(2)
job = client.extract.get(job.id)
print(job.extract_result)

Use the agentic tier for mixed content: If you need to extract both tabular and non-tabular elements in a single pass, the agentic tier uses more capable models that handle complex layouts better. Note that this approach uses more credits (15/page vs 5/page).

Don’t embed business logic in field descriptions. Extract clean data first, then compute in your application code.

# ❌ Problematic: Too much logic in the field description
problematic_field = {
"calculated_score": {
"type": "number",
"description": "If revenue > 1M, multiply by 0.8, else if revenue < 500K multiply by 1.2, otherwise use the base score from table 3, but only if the date is after 2020 and the category is not 'exempt'"
}
}
# ✅ Better: Simple extraction, handle logic separately
better_schema = {
"revenue": {"type": "number", "description": "Total revenue in dollars"},
"base_score": {"type": "number", "description": "Base score value from the scoring table"},
"date": {"type": "string", "description": "Date in YYYY-MM-DD format"},
"category": {"type": "string", "description": "Business category"}
}
# Then handle calculations in your application code:
def calculate_final_score(extracted_data):
revenue = extracted_data["revenue"]
if revenue > 1000000:
return extracted_data["base_score"] * 0.8
elif revenue < 500000:
return extracted_data["base_score"] * 1.2
return extracted_data["base_score"]
Note for AI agents: this documentation is built for programmatic access. - Overview of all docs: https://developers.llamaindex.ai/llms.txt - Any page is available as raw Markdown by appending index.md to its URL — e.g. https://developers.llamaindex.ai/llamaparse/parse/getting_started/index.md - Agent-friendly REST search APIs live under https://developers.llamaindex.ai/api/ — search (BM25 full-text), grep (regex), read (fetch a page), and list (browse the doc tree). See https://developers.llamaindex.ai/llms.txt for parameters. - A hosted documentation MCP server is available at https://developers.llamaindex.ai/mcp. If you support MCP, you can ask the user to install it for browsing these docs directly (an alternative to the REST API). Setup: https://developers.llamaindex.ai/for-agents/mcp/ - Other LlamaIndex tooling for agents — the LlamaParse Platform MCP server, agent skills and plugins, and the n8n node — is mapped at https://developers.llamaindex.ai/for-agents/