Contractex
Contractex is a Python library for legal document intelligence: the processing layer for chunking, extraction, retrieval, privacy enforcement and quality measurement that legal AI products are built on.
This project aims to democratise legal tech by building a transparent open-source library that changes who within the legal field gets to benefit from the latest developments in machine learning and AI.
pip install contractex
Documentation: quietsignalslab.com/contractex/docs
What it does
- Parses contracts deterministically: sections, defined terms, cross-references.
- Extracts parties, clauses and terms with the model you choose: a local model through Ollama, or OpenAI, Anthropic or Google.
- Traces an extracted value back to character offsets in the source.
- Enforces a privacy profile on every model call.
- Measures quality with an evaluation harness and CI gates.
What it refuses to do
- Put the text of a
secretdocument into any model prompt. - Send a
restricteddocument to anything but a local model. - Send
confidentialtext to a model without redacting the personal data it detects. - Pick a model vendor for you, or install one's SDK unless you ask for it.
from contractex import LegalDoc
from contractex.privacy import PrivacyBlockedError, PrivacyProfile
from contractex.tasks import TaskRegistry
doc = LegalDoc(
full_text="Board minutes: acquire Acme Corp for $4.2bn. Contact 415-555-0132.",
privacy_profile=PrivacyProfile(sensitivity="secret"),
)
pipeline = TaskRegistry.default().build_pipeline(
["pii_detection", "summarization"],
task_kwargs={"summarization": {"llm_provider": "llama3.1:8b"}}, # a local Ollama model
)
try:
pipeline.run(doc)
except PrivacyBlockedError:
print("blocked before any prompt reached the model")
blocked before any prompt reached the model
Measured, not claimed
Generated by python -m benchmarks and checked in CI. Methodology and
limitations are in the benchmarks documentation.
| 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 |
Limits
Without Presidio (contractex[privacy]),
names are not detected. Scanned PDFs need OCR (contractex[ocr]). Patterns
for chunking, citations and personal data are English-centric. The full list
is on the Limitations
page.
Project
Changelog · Contributing · Security · Apache License 2.0 · maintained by Quiet Signals Lab
Metadata
Release files for contractex 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| contractex-0.5.0.tar.gz | 210.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| contractex-0.5.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 438.9 kB
Release files / contractex-0.5.0.tar.gz
| Download URL | contractex-0.5.0.tar.gz |
|---|---|
| Size | 210.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ad87480b6a41fe3565ab7f9e10a273a86f30f56baf5ff219ecfd28e6942026a9
|
|
BLAKE2b-256 checksum How to use checksums |
f5b5f42bf37d869e45625660b0a5c1c44c6238e9689f3a8be1f4b41c1ee9b894
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 12, 2026.
Transparency logRelease files / contractex-0.5.0-py3-none-any.whl
| Download URL | contractex-0.5.0-py3-none-any.whl |
|---|---|
| Size | 228.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5a14ff205d65e27932e732424c8588bf7a6bb7a0a82dd96d20aeadcfc23fe816
|
|
BLAKE2b-256 checksum How to use checksums |
0424d5f28ef80869d8e7aa39126ca8f55169d9f8cf278460930d624b35e8fc79
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 12, 2026.
Transparency log