Skip to content

Repository files navigation

PyPI Python Tests License

Contractex

Contractex is a Python library for legal document intelligence. It provides the processing layer that legal AI products are built on: chunking, extraction, retrieval, privacy enforcement and quality measurement. It is not an application.

Most serious legal tooling is closed-source or built in-house at large firms. That leaves small practices, clinics and advice organisations dependent on vendors. An open, auditable processing layer lets them build their own, and measure whether it is accurate enough to rely on.

pip install contractex

Design principles

Principle In the code Measured by
The deterministic/probabilistic boundary is explicit. Every task declares whether it calls a model; the task table says what happens when the output is poor. Structure parsing, PII detection, citation extraction, classification and playbook checks make no model calls. Tests on the deterministic parts; the evaluation harness for the rest.
Every extracted value is traceable to its source. ClauseAwareChunker returns exact substrings; ProvenanceTracker resolves a value to character offsets in the original document. Provenance benchmark on CUAD.
Privacy is enforced in code at the call site. A PrivacyProfile on each document; PrivacyAwareLLMRouter blocks, rejects or redacts on every model call made by tasks, pipelines and RAG. No provider is ever chosen for you. Routing matrix and privacy tests.
Quality is measurable and gateable. EvalHarness scores any extraction function against labelled suites; assertions fail CI when accuracy drops. The benchmarks, regenerated by one command and checked in CI.

What Contractex refuses to do

  • Put the text of a secret document into any model prompt.
  • Send a restricted document to anything but a local model (LocalProvider).
  • Send confidential or restricted text to a model without redacting the personal data it detects.
  • Choose a model vendor for you: a task that needs a model and was not given one raises an error.
  • Install any model vendor's SDK unless you ask for it.

Where it stops

Without Presidio installed, names are not detected. Scanned PDFs need OCR. Chunking and citation patterns are English-centric. The Limitations page lists everything known.

Start here

  • Installation: what to install for your setup.
  • Quick start: parse, redact, chunk and run tasks on a sample NDA.
  • Privacy model: what each sensitivity level enforces, and where.
  • Benchmarks: chunking, provenance and privacy, measured.

Contractex is open source under the Apache License 2.0 and maintained by Quiet Signals Lab.

Measured

Generated by python -m benchmarks and checked in CI.

Measured on Result
Gold clause spans kept in one chunk (102 CUAD contracts, 512-token chunks) clause aware 98.9% · semantic 95.5% · fixed window 88.6%
Verbatim values traced to the right place in the source 97.2%
Privacy routing checks (4 sensitivity levels × 2 providers × 4 entry points) 32 of 32 pass

Changelog · Contributing · Security

About

Open-source Python library for legal document intelligence: privacy enforced in code, quality measured.

Topics

Resources

Contributing

Security policy

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages