AI Legal-Document Extraction (Claude + Mastra Evals)
Overview
An AI-powered tool that extracts structured data from legal PDF documents. A Node/Express API uploads PDFs and uses Anthropic’s Claude Opus 4 to read and extract their contents, a React/Vite client provides the upload and review UI, and a Mastra-based harness evaluates extraction quality against test cases.
The Challenge
Legal documents are dense, inconsistent, and high-stakes. Turning them into reliable structured data needs strong document understanding, post-processing to clean and group the output, and, critically, an evaluation loop to measure whether the AI’s extractions are actually correct.
What We Built
Three parts. The server (pdf-text-extraction-api, Express, type: module) accepts uploads via Multer and calls Claude through @anthropic-ai/sdk, with utilities to filter zero values and perform programmatic grouping of extracted fields, plus Firebase integration. The client is a React + Vite app (Radix UI, Tailwind, react-dropzone, react-pdf, TanStack Query, Zustand, ExcelJS/PapaParse for CSV/XLSX export) for uploading and reviewing results. The mastra package runs an evaluation harness (@mastra/core + @mastra/evals, with an OpenAI-backed judge via @ai-sdk/openai) over numbered test suites under tests/, reading CSV/XLSX fixtures.
Technologies & Approach
Claude Opus 4 via the Anthropic SDK does the heavy document extraction; Express + Multer handle uploads; Firebase persists data. The React/Vite front end renders PDFs and exports results to spreadsheets. Mastra provides a structured eval framework so extraction accuracy is measured rather than assumed.
Outcome / Impact
A working build that validates LLM-based extraction of structured data from legal PDFs, complete with a review UI, spreadsheet export, and, notably, a dedicated evaluation harness to quantify quality. Demonstrates the studio’s ability to build measurable, production-minded AI document pipelines.
Capabilities Demonstrated
- LLM-driven extraction of structured data from PDFs (Claude Opus 4)
- Document-processing APIs with upload handling and post-processing
- LLM evaluation harnesses (Mastra evals with an LLM judge)
- PDF rendering, review UI, and CSV/XLSX export
- Firebase-backed full-stack delivery