Skip to content

Repository files navigation

Legal Co-Pilot

The AI-powered contract intelligence platform — read, analyze, redline, act, and remember.

What it does

Legal Co-Pilot reads any contract and gives you everything you need to negotiate it well:

  • Reads any contract — native PDFs, scanned documents, signature pages, multi-page tables. Every clause, party, date, and obligation is extracted into structured, searchable data.

  • Identifies risks intelligently — auto-renewal traps, weak liability caps, hostile termination terms, IP grabs, vague indemnification, missing standard protections. Each risk comes with a clear explanation of why it matters and how severe it is.

  • Drafts your response — for every flagged risk, you get suggested counter-language and a ready-to-send negotiation email that matches your past tone with this counterparty.

  • Takes action when you approve — sends contracts for signature, files them in your contract management system, sets calendar reminders for obligation deadlines, and emails the counterparty.

  • Remembers across contracts — the second time you review a contract from the same counterparty, Legal Co-Pilot surfaces what you negotiated last time, what you accepted, and what they typically agree to.

Architecture

flowchart LR
    PDF[Contract PDF] --> EXT[Extraction<br/>Agent]
    EXT --> CONTRACT[Structured<br/>Contract<br/>Pydantic]
    CONTRACT --> RISK[Risk<br/>Analyzer]
    RISK --> REPORT[Risk Report<br/>severity + confidence]
    REPORT --> RED[Redline<br/>Drafter]
    RED --> EMAIL[Negotiation<br/>Email]
    REPORT --> ACTION[Action Layer<br/>MCP]
    ACTION --> SIG[E-signature]
    ACTION --> CAL[Calendar]
    ACTION --> FILE[Filing]
    CONTRACT --> MEM[(Long-term Memory<br/>Neon + pgvector)]
    REPORT --> MEM
    MEM -.recall counterparty.-> RISK

    subgraph Router [Provider-Agnostic LLM Router]
        GEM[Gemini]
        GROQ[Groq]
        OC[Ollama Cloud]
        OL[Ollama Local]
    end

    EXT -.calls.-> Router
    RISK -.calls.-> Router
    RED -.calls.-> Router

    classDef store fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#000
    classDef router fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#000
    classDef io fill:#d1fae5,stroke:#059669,stroke-width:1.5px,color:#000
    class MEM store
    class Router,GEM,GROQ,OC,OL router
    class PDF,SIG,CAL,FILE,EMAIL io
Loading

Sample Run

Real output from running the full pipeline against a synthetic Master Services Agreement (Acme Corp ↔ Beta LLC). One command, end-to-end, no human in the loop.

$ legalcopilot-demo --pdf contract.pdf

== Contract summary ==
  Parties:           Acme Corp, Beta LLC
  Effective date:    January 1, 2026
  Governing law:     State of Delaware
  Clauses extracted: 6
  Obligations:       1
  Signatures:        2

== Risk findings ==  3 total: 2 HIGH, 1 MEDIUM

  [HIGH]   Missing confidentiality clause                    (95% confidence)
           Without explicit confidentiality terms, sensitive shared
           information has no contractual protection.
           > Add a mutual confidentiality clause covering trade secrets,
             customer data, and non-public business information; survive
             termination by 3-5 years.

  [HIGH]   Missing termination clause                        (95% confidence)
           Without a clear termination right, exiting the contract may
           require legal action or be impossible without breach.
           > Add a termination-for-convenience clause with a reasonable
             notice period (30-90 days) and a termination-for-cause clause
             with 30-day cure period.

  [MEDIUM] Missing indemnification                           (95% confidence)
           > Add mutual indemnification for IP infringement, gross
             negligence, and willful misconduct, with reasonable defense + cap.

Each finding ships with severity, confidence score, an explanation a non-lawyer can read, and a concrete drafted action — not just a flag. The full output (including the auto-drafted negotiation email) is saved to docs/data/sample_demo_run.md.

Cross-Provider Benchmark on CUAD

Real numbers from a head-to-head bench run on the public CUAD legal dataset (n=5 contracts, restricted to the 10 clause categories the project's schema covers). Same prompt, same scoring, two providers — Gemini 2.5 Flash vs. Groq Llama 3.3 70B (free tier on both).

Cross-provider CUAD benchmark

Headline: Groq beats Gemini on accuracy and latency — 30.8% F1 vs. 8.0% F1, and 15.4s vs. 269.1s total runtime. On individual clause types where matching is unambiguous, Groq hits 100% precision on governing_law, auto_renewal, and liability_cap with 50–100% recall.

Honest scoring caveats:

  • Substring-based span matching is conservative — it misses semantically-correct extractions whose phrasing diverges from CUAD's gold-labeled span. Expected real-world accuracy is higher than these numbers.
  • n=5 is a smoke run; full 30-contract benchmark is a planned follow-up.
  • Failure rate (Gemini 2/5 timeouts, Groq 3/5 rate-limits on free tier) lowers coverage; the numbers reflect strict accounting of partial runs.

Reproduce locally:

bash scripts/download_cuad.sh   # one-time; ~440 MB
GOOGLE_API_KEY=... GROQ_API_KEY=... \
  legalcopilot-bench --providers gemini,groq --limit 5 \
    --timeout-secs 180 --max-chars 30000 \
    --output docs/data/cuad_smoke.md
python scripts/generate_charts.py

End-to-End Latency

A real run of the full pipeline against a synthetic Master Services Agreement, using the multi-provider router (Gemini primary, Groq fallback). Total wall-clock time was ~62 seconds for one contract end-to-end — extract → risk analysis → redlines → drafted negotiation email — producing 6 clauses, 3 high-severity risks, 2 medium-severity risks, and a ready-to-send email.

End-to-end pipeline latency

Reproduce locally:

GOOGLE_API_KEY=... GROQ_API_KEY=... \
  python scripts/measure_pipeline.py --pdf path/to/contract.pdf
python scripts/generate_charts.py

Test Coverage

The codebase ships with 212 unit tests across 8 modules, all passing in CI on every push to main. Tests use mocked providers so the suite runs without API keys or network access.

Unit test coverage by module

Module Tests What it covers
LLM Router & Providers 76 Routing, fallback chains, rate-limit handling, Gemini + OpenAI-compatible providers
Extraction Pipeline 43 PDF parsing, schema validation, extraction agent, eval harness
Long-Term Memory 27 pgvector-backed memory store, retrieval, counterparty scoping
Risk Analysis 21 Risk taxonomy, severity scoring, missing-clause detection
Eval Harness (CUAD) 13 CUAD dataset loader, bench CLI
Action Layer (MCP) 12 MCP tool protocol, permission gate, action dispatch
Redline & Email 11 Redline generation, negotiation email drafter
API & Demo CLI 9 FastAPI health, demo CLI, configuration

Who it is for

  • SMB founders and operators signing inbound vendor and customer contracts without in-house legal
  • Solo legal practitioners handling high contract volume across diverse clients
  • Procurement teams at mid-market companies running structured vendor evaluations
  • In-house counsel managing contract lifecycle for ongoing relationships

Why this exists

Existing AI legal tools cost $50–500+/seat/month, lock you into one vendor's models, and give you opaque "summaries" without showing why. Most are single-shot — upload PDF, get text back, you do the rest. None remember what you decided last quarter. None can take action on your behalf. None tell you which model decided what.

Legal Co-Pilot is different:

Other tools Legal Co-Pilot
Cost $50–500+/seat/month Free
Model choice Vendor-locked You choose — bring your own keys
Reasoning Opaque You see the chain of thought
Action layer Read-only summaries Sends emails, signatures, sets reminders
Memory Stateless Learns counterparties over time
Privacy Cloud-only Local model mode available

Status

Currently in active development. First public release coming soon.

A reproducible accuracy benchmark on the CUAD legal dataset (precision/recall by clause type across all configured providers) is planned and will be added to this README once published.

License

MIT

About

Open-source multi-provider AI Legal Operations Co-Pilot — multi-modal contract analysis, reasoning-driven risk identification, agentic actions, and long-term memory. Free-tier only.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages