ClaimFlow AI is a document-intake workflow for insurance claims.
It lets a user upload a claim PDF or paste claim email text, extracts structured claim JSON using Gemini, validates the extracted data with deterministic rules, saves the run in Postgres, and shows a traceable timeline.
Supported inputs:
- PDF claim document
- Pasted email text
Current output:
- Structured claim JSON
- Model and prompt version
- Confidence JSON
- Missing fields
- Conflicts and warnings
- Required evidence
- Final status:
COMPLETEDorNEEDS_REVIEW - Saved extraction run
- Timeline events
- Turborepo
- Next.js
- TypeScript
- Prisma
- Postgres
- Zod
- Gemini API
- Zustand
PDF / email text
→ Document row
→ ExtractionRun row
→ DOCUMENT_UPLOADED event
→ Run extraction
→ Gemini extraction
→ Zod-parsed structured JSON
→ extractedJson saved in Postgres
→ status moves to VALIDATING
→ Run validation
→ deterministic rules check missing fields, conflicts, warnings, and evidence
→ validationJson + missingFieldsJson saved in Postgres
→ status becomes COMPLETED or NEEDS_REVIEW
→ validation result + timeline shown in UIImplemented:
- Turborepo setup
- Next.js app
- Prisma + Postgres
- Shared Zod schemas
- DB models:
documentsextraction_runsextraction_events
Implemented:
- PDF upload
- Email text submission
- Local PDF storage
POST /api/documents/upload- Run creation with
UPLOADEDstatus - Dashboard recent runs list
- Run detail timeline
Implemented:
@repo/aipackage- Gemini client
- Prompt versioning
- PDF extraction
- Email text extraction
POST /api/extraction-runs/[runId]/extract- Manual Run extraction button
- Extracted JSON panel
- Timeline events:
EXTRACTION_STARTEDMODEL_RESPONSE_RECEIVEDEXTRACTION_COMPLETEDRUN_FAILED
Implemented:
- Deterministic claim validation after extraction
validateClaimExtraction()shared validation servicePOST /api/extraction-runs/[runId]/validate- Manual Run validation button
- Missing fields detection
- Conflicts and warnings detection
- Required evidence detection
- Final status:
COMPLETEDNEEDS_REVIEW
- Saved
validationJsonandmissingFieldsJson - Validation summary UI
- Missing fields UI
- Conflicts, warnings, and required evidence UI
- Timeline events:
VALIDATION_STARTEDVALIDATION_COMPLETEDMISSING_FIELDS_DETECTEDCONFLICTS_DETECTEDRUN_COMPLETEDRUN_NEEDS_REVIEW
Day 4 flow:
Upload PDF or paste email text
→ created run
→ click Run extraction
→ Gemini extracts structured claim JSON
→ app saves extractedJson
→ status moves to VALIDATING
→ click Run validation
→ app checks missing fields, conflicts, warnings, and required evidence
→ app saves validationJson and missingFieldsJson
→ status becomes COMPLETED or NEEDS_REVIEW
→ UI explains the result
→ timeline proves what happenedTested with synthetic PDFs:
- valid own-damage claim →
COMPLETED - missing policy number →
NEEDS_REVIEW - repair estimate only →
NEEDS_REVIEW - third-party without police report →
NEEDS_REVIEW - theft claim missing FIR →
NEEDS_REVIEW
Completed lifecycle:
UPLOADED
→ EXTRACTING
→ VALIDATING
→ COMPLETEDNeeds-review lifecycle:
UPLOADED
→ EXTRACTING
→ VALIDATING
→ NEEDS_REVIEWFailure lifecycle:
UPLOADED / FAILED
→ EXTRACTING / VALIDATING
→ FAILEDDATABASE_URL=postgresql://postgres:postgres@localhost:5432/claimflow_ai?sslmode=disable
GEMINI_API_KEY=
GEMINI_MODEL=gemini-2.5-flashFor local extraction, keep Gemini variables in:
apps/web/.env.localbun install
bun run db:migrate
bun run devApp runs at:
http://localhost:3001Week 2:
- Add human review queue
- Show runs that need review
- Allow reviewer decisions
- Store reviewer notes and corrections
- Use reviewer feedback later for memory/rule improvement