AI Legal Assistant

A stream-first legal document analysis assistant that processes uploaded PDFs through extraction, note generation, precedent retrieval, comparison, and staged prediction refinement.

FastAPICrewAIPineconeSSELegal AI
AI Legal Assistant cover

Timeline

Built through 2025 as an iterative legal-tech backend, then upgraded to a streaming architecture with structured step events and artifact persistence.

Role & Scope

Owned backend design and implementation across file ingestion, legal-note generation, retrieval/comparison orchestration, SSE stream contracts, and JSON artifact outputs consumed by the frontend.

Team Setup

Worked in a small product loop with legal-domain stakeholders and frontend collaborators to tune progress events, output schema, and review usability.

Context

Problem: Batch-style legal analysis flows produced delayed final answers with little transparency into intermediate extraction, retrieval, and reasoning quality.

Solution: Implemented a FastAPI `/process_doc_stream` pipeline backed by `StreamingLegalCaseProcessor`, using SSE events, token-aware chunking (`cl100k_base`), Pinecone similarity lookup, multithreaded case comparison, and incremental prediction refinement.

Impact: Turned opaque document processing into a live, inspectable workflow with persisted step artifacts (`01_text_extraction` to `05_legal_predictions`) and end-of-run aggregated output (`00_complete_results.json`).

Implementation Details

Architecture

FastAPI streams `/process_doc_stream` events while `StreamingLegalCaseProcessor` executes a 5-stage flow: PDF parsing (`Pdf2MD`), key-point extraction (`PointGetter`), token-budget chunking, vector retrieval (`CasesVectors.get_facts_from_note`), threaded comparison (`LegalCaseComparisonAgent` via `ThreadPoolExecutor`), and sequential prediction/refinement (`LegalDecisionPredictorAgent`).

Data & Evaluation

Evaluated output quality through chunk coverage, key-point relevance, similarity hit usefulness, and consistency of refined predictions across comparison batches, supported by per-step logs and JSON outputs.

Production & Ops

Shipped with Docker Compose (Next.js + FastAPI), strict PDF validation/cleanup, low-latency streaming headers (`text/event-stream`, disabled buffering), and session log files (`streaming_legal_case_*.log`) for debugging.

Lessons Learned

Legal users trusted the system more when intermediate artifacts were explicit and replayable; streaming transparency was as important as final prediction quality.

Links

Last verified: September 1, 2026

Demo on Request

Public Evidence

Last verified: September 1, 2026

This case study summarizes production work delivered under private repositories and confidentiality constraints. Public artifacts are intentionally omitted while keeping the implementation narrative transparent.

LFM2.5-2.6B Fable5 Coding AgentJurai Assurance — AI Flight Claim Assessment