Skip to main content

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

Privacy is enforced on model calls made through the built-in tasks, pipelines, retrieval and the router. Code that calls ContractExtractor or a provider directly is not covered. "Local" means a LocalProvider whose Ollama server is on your machine or a private network and whose model is not an Ollama cloud model. Without Presidio installed, names are not detected; with it, about one name token in five is still left, and most addresses and reference numbers are (see the benchmarks). Treat redaction as a reduction of exposure, not a guarantee.

Scanned PDFs need OCR. Chunking and citation patterns are English-centric. Extraction accuracy per model is not yet benchmarked. 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
Person-name tokens left after redaction (980 synthetic English documents) built-in patterns 99.2% · with Presidio 18.0%
Address and reference-number tokens left, with Presidio addresses 62.5% · reference numbers 92.2%

Changelog · Contributing · Security

Metadata

Release files for contractex 0.6.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for contractex 0.6.1
File Size Uploaded Provenance Actions
contractex-0.6.1.tar.gz 299.0 kB With provenance Details for contractex-0.6.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for contractex 0.6.1
File Interpreter ABI Platform Actions
contractex-0.6.1-py3-none-any.whl Python 3 none any Details for contractex-0.6.1-py3-none-any.whl

Total release size: 525.5 kB

Release files / contractex-0.6.1.tar.gz

Download URL contractex-0.6.1.tar.gz
Size 299.0 kB
Tags Source
SHA-256 checksum
How to use checksums
858602e105635c631cb908a91708bf00e559c3a4c8228e3a9120f04c2f1cc3a1
BLAKE2b-256 checksum
How to use checksums
3a1978fd086747c12eb1b062ebf06fde3e4f06df56837c4434030bbf5ec293e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

Release files / contractex-0.6.1-py3-none-any.whl

Download URL contractex-0.6.1-py3-none-any.whl
Size 226.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b23111ce62f065f70036352158700ec8fd841c5db569f0cd5f5ac62b43fc1d29
BLAKE2b-256 checksum
How to use checksums
c4d9737dd11efba880d522208d5b1500c2bf98b769a92a221c07ba7ed97af5e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

Security for contractex 0.6.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for contractex-0.6.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page