extract.run() method pulls specific fields from documents as structured JSON. You define a JSON schema with the fields you need, and Extract returns values matching that schema.
Basic Usage
Method Signature
Parameters
Settings Options
Schema Definition
Theinstructions parameter requires a schema field with a JSON schema:
Field Descriptions
Field descriptions are critical for accurate extraction. Be specific:System Prompt
Add document-level context withsystem_prompt:
Input Options
Extract accepts multiple input formats:Deep Extract
For documents with repeating data (line items, transactions) or complex/long extractions, enable Deep Extract (higher cost and latency). It supersedes the deprecatedarray_extract:
Array Extraction Guide
Detailed guide to array extraction configuration.
Citations
Enable citations to get source locations for each extracted value:Parsing Configuration
Since Extract runs Parse internally, you can configure parsing:input is a jobid:// reference.
Response Structure
With Citations
When citations are enabled, the response format changes. Instead of a list,result.result is a dict with values wrapped in citation objects:
Schemaless Extraction
You can also extract without a schema using only a system prompt:Error Handling
Complete Example
Best Practices
Write Clear Descriptions
Field descriptions directly impact extraction quality. Be specific about location and format.
Use Deep Extract
Enable
deep_extract for complex documents or many repeating items (transactions, line items). Higher cost/latency. Supersedes the deprecated array_extract.Enable Citations for Verification
Use citations to verify extracted values and show users source locations.
Debug with Parse First
If extraction fails, check the Parse output first. Extract can only find what Parse sees.
Troubleshooting
Missing values
Missing values
If expected fields are empty:
- Check the Parse output:
client.parse.run(input=upload.file_id) - Verify the value appears in the parsed content
- Improve field descriptions to match how values appear
- Try enabling
deep_extractfor long or complex documents
Hallucinated values
Hallucinated values
Extract only returns what’s on the document. If you need computed values, extract raw data and compute in your code:
Next Steps
- Learn about schema design best practices
- Explore array extraction for long documents
- Check out citations for source verification
- See the async client for concurrent processing