This project processes automotive insurance parts guidelines (e.g., Allstate policy documents) and validates whether specific parts are allowed, not allowed, or have limited usage based on their type (OEM, Aftermarket, or Recycled).
This project uses:
- LlamaIndex: Document parsing and extraction
- Vercel AI SDK: AI SDK from Vercel with Claude Sonnet 4.5
- Zod: Schema validation
- PDF Extraction: Uses LlamaExtract API with MULTIMODAL mode to extract structured parts guidelines from PDF documents
- AI Classification: Leverages Claude Sonnet 4.5 to match specific part names to validation table entries
- Batch Processing: Processes parts in batches with automatic retry logic
Note: This project uses bun as the package manager. You can use your preferred package manager like npm or pnpm.
bun installCreate a .env file in the src directory:
LLAMA_CLOUD_API_KEY=your_llama_cloud_api_key
ANTHROPIC_API_KEY=your_anthropic_api_keycd srcbun run index.tsThis will:
- Extract parts guidelines from the PDF using LlamaExtract and save to
src/data/validationTable.json - Match input parts to validation table entries using Claude and save to
src/data/partsWithValidationTableNames.json - Determine status (Allowed/Not Allowed/Limited) for each part
- Save results to
src/data/partsWithStatus.json
I have added two html files to visualize the results:
src/visualizeValidationTable.html: Visualizes the validation table(rules from Allstate policy)src/visualizePartsWithStatus.html: Visualizes the parts with their status
Edit src/index.ts to control behavior:
const RERUN = true // Set to false to use saved extraction resultspart-bay/
├── src/
│ ├── data/
│ │ ├── parts.json # Input parts to validate
│ │ ├── extracted_parts.json # Extracted guidelines from PDF
│ │ ├── partsWithValidationTableNames.json # Parts matched to validation table
│ │ └── partsWithStatus.json # Final validation results
│ ├── constants.ts # Configuration constants
│ ├── schemas.ts # JSON schema for extraction
│ ├── utils.ts # LlamaExtract API and other utilities
│ ├── index.ts # Main application entry point
│ └── visualizeValidationTable.html # Visualization tool
│ └── visualizePartsWithStatus.html # Visualization tool
├── .env # API keys (not committed)
├── package.json
└── README.md
The system uses LlamaExtract with the following configuration:
- Extraction Mode: MULTIMODAL (for visually rich documents)
- Extraction Target: PER_DOC (processes entire document)
- Chunk Mode: PAGE (processes page by page)
// Extraction agent configuration
{
extraction_mode: "MULTIMODAL",
extraction_target: "PER_DOC",
chunk_mode: "PAGE",
invalidate_cache: true
}The extracted guidelines are saved to src/data/validationTable.json.
Parts are matched to validation table entries using Claude Sonnet 4.5:
- Processes in batches of 50 parts
- Automatic retry logic (up to 3 attempts)
- Strict enum validation against known part names
For each part, the system:
- Looks up the matched validation table entry
- Checks the part type (OEM, Aftermarket, or Recycled)
- Returns the corresponding status
{
"name": "L Frt Pickup Bed Brace",
"type": "OEM"
}{
"parts": ["supports", "brackets"],
"oem_opt_oem": "Allowed",
"certified_aftermarket": "Allowed",
"recycled_parts": "Not Allowed"
}{
"name": "L Frt Pickup Bed Brace",
"type": "OEM",
"validationTablePartName": "supports",
"status": "Allowed"
}This project was created using bun init in bun v1.2.1.