All projects

Professional Services

Harvey

Enterprise legal AI and contract intelligence platform

Built the legal RAG pipeline behind cited document Q&A, contract analysis and document extraction across PDFs and scanned files, plus the fine-tuned clause classifier and evaluation runs, for Harvey's enterprise legal AI platform.

Harvey: enterprise legal AI and contract intelligence platform

1 / 5
Harvey: enterprise legal AI and contract intelligence platform

Harvey: enterprise legal AI and contract intelligence platform

0.90–0.94

Clause classifier macro-F1

90–95%

Lower cost per clause (fine-tuned)

88–94%

Retrieval recall@10

Stack

Python / FastAPIAzure OpenAI (GPT-4, GPT-3.5 Turbo)Fine-tuned GPT-3.5 TurboOpenAI embeddingsLangSmithAzure AI Content SafetyPostgreSQLRedisAzure AKS

Overview

Harvey is an enterprise legal AI platform that helps law firms and in-house legal teams research, review, analyze and draft legal work. Answers are grounded in the matter's own documents and cite the exact document, page, clause and passage they came from.

The central idea: the model answers only from passages retrieved from the firm's own documents, and every answer links back to its source, so a lawyer can check it in seconds.

The problem

A single matter can hold contracts, emails and thousands of pages of due-diligence material, which lawyers search, compare and summarize by hand.

  • Slow document review: locating provisions takes hours, and the effort grows with every document.
  • Repetitive contract analysis: the same questions are asked across NDAs, MSAs and purchase agreements.
  • Trust: an answer a lawyer cannot check against the source document is an answer they cannot use.

My role

I worked at Harvey as an AI engineer on LLMs, RAG and document intelligence. I built or owned the retrieval pipeline behind document Q&A (semantic chunking, dense retrieval and re-ranking), cited answers and multi-document summaries, contract analysis and information extraction across PDFs, tables and scanned forms, the fine-tuned clause classifier, and the evaluation runs for model and prompt changes. The wider team built document ingestion and OCR, vector storage, connectors, security and identity, infrastructure, and Harvey's model research.

What I built

Legal RAG pipeline

  • Semantic chunking that follows document structure (sections, clauses, defined terms and tables) instead of fixed-size windows, so a retrieved passage carries the context a clause needs.
  • Dense retrieval with a re-ranking stage, so answers draw on the clause that actually governs, not the one that merely sounds closest.
  • Answers that cite document, page and passage, and say so when retrieval finds no support instead of guessing.

Contract analysis and document extraction

  • Contract analysis that checks agreements clause by clause against the positions in a firm's playbook.
  • Information extraction and multi-document summarization across PDFs, tables and scanned forms, asking the same question of every document in a matter.
  • Prompt engineering for legal tasks, tuned against lawyer-labeled examples to raise accuracy and cut hallucinations.

Fine-tuned clause classifier and evaluation

  • Supervised fine-tuning of GPT-3.5 Turbo on SEC EDGAR exhibits and lawyer-drafted agreements, with every clause labeled by two lawyers and no customer data.
  • Classifier labels route each clause to the right analysis prompt, keeping contexts small.
  • A promotion rule (macro-F1 at least that of prompted GPT-4, no clause-type regression) and evaluation runs on lawyer-labeled golden sets for every model and prompt change, tracking retrieval recall, citation accuracy and hallucination rate.

Results

  • Clause classifier: the fine-tuned GPT-3.5 Turbo reached a macro-F1 of 0.90–0.94 on the held-out test set, 3–6 points above prompted GPT-4, at 90–95% lower cost per clause.
  • Retrieval: recall@10 of 88–94% on the retrieval set.

Tech stack

LayerTechnologies
BackendPython, FastAPI, Pydantic, SQLAlchemy 2.0, Harvey Job Framework
AI engineRetrieval pipeline (semantic chunking, dense retrieval, re-ranking), LangSmith, Azure AI Content Safety
ModelsGPT-4, GPT-4 Turbo, GPT-3.5 Turbo and fine-tuned GPT-3.5 Turbo (Azure OpenAI), OpenAI text-embedding-ada-002
DataAzure Database for PostgreSQL, Redis, Azure Blob Storage
InfrastructureAzure Kubernetes Service, Terraform, Helm, OpenTelemetry, Datadog

Related case studies