Traffic-law extraction

DriveLegal

An offline pipeline that converts Indian traffic-law PDFs into grounded, SQLite-ready legal records and a local question-answering dashboard.

Problem / itch

Indian traffic-law information lives in PDFs, tables, state rules, amendments, and messy source documents. The itch was simple: make a driver or builder ask a concrete fine/rule question and get an answer backed by page-level source evidence.

What I built

  • Discovered PDFs recursively, hashed documents, rendered pages, and used LightOnOCR or MiniCPM for page/table reading.
  • Parsed OCR HTML/Markdown tables into strict Pydantic records, normalized jurisdictions and violation labels, and preserved original wording.
  • Grounded extracted rows against exact PDF text where available, corrected OCR drift deterministically, and wrote JSON-per-PDF plus consolidated JSONL.
  • Built SQLite ingest, read-only SQLite agent tools, FastAPI endpoints, and a Vite dashboard with map/geocoding support.

Results

Current checked extraction report processed 3 traffic fine PDFs and extracted 175 legal records with 0 partial documents, 0 failed documents, and 0 marked for human review.

Quality report: 175 JSONL records validate against the schema, 0 accepted records have empty source quotes, 0 accepted quotes failed page grounding after whitespace normalization, and 0 accepted numeric fine amounts mismatched the first visible numeric amount in raw fine text.

Coverage was strong for Delhi traffic offences 2026 at 98.6%, but weak for Mumbai at 30.5% and Kolkata at 26.4%, exposing the next parser bottleneck honestly.

The system produces per-document structured records, a consolidated legal-record dataset, a queryable SQLite database, and grounded answers that cite the source document and page.

Status

Local pipeline and dashboard implemented under DriveLegal.

Links