This release is a pre-release and may not be stable for production use.
Tabula Razer
OpenContracts' structured data extraction pipeline as a standalone Python package. Choose a fieldset (a group of extraction columns) and a set of documents. The CLI reads from an OpenContracts-compatible GraphQL server or an offline JSON bundle and writes one JSONL file per runnable column.
out/
├── effective-date.jsonl ← column "Effective Date"
├── governing-law.jsonl ← column "Governing Law"
├── parties.jsonl ← column "Parties"
└── manifest.json ← run scope, model, file names, and counts
Architecture
- Source. A
DocumentSourceresolves the fieldset and document selection. The GraphQL and bundle adapters expose the same interface. - Runner and index. The asyncio runner limits concurrency, loads each
document's text and annotations once, and shares its in-memory
DocumentIndexacross the selected columns. Parent IDs form the section hierarchy. The index supports keyword search and section traversal, with optional semantic search delegated to the source. - Extraction engine. A pydantic-ai agent extracts one field from one document at a time. It builds a prompt from the column's query, examples, and fenced constraints. Short documents with full text can be included in the prompt. The engine validates the typed result and grounds extracted strings in the document text when possible.
- Writer. The CLI streams results to local JSONL files and records run state in the manifest.
The OpenContracts server's doc_extract_query_task imports the package's
shared prompt assembly, output parsing, diagnostics, and text alignment.
The server runs its own ORM-backed extraction and persists Datacell records.
See the OpenContracts integration.
Install
pip install "tabula-razer[openai] @ git+https://github.com/Open-Source-Legal/tabula-razer.git"
# From a clone of this repository:
pip install -e ".[all,test]"
Python 3.10+, Linux / macOS / Windows. Provider keys come from the usual
environment variables (OPENAI_API_KEY, ANTHROPIC_API_KEY, ...).
Upstream requirements
For a live run, supply an OpenContracts server base URL or its GraphQL
endpoint with --api-url. The server must expose the
GraphQL reads below and have a fieldset and processed
documents available to the caller. A corpus run requires read access to both
the corpus and the documents. Use a bearer JWT or an API key
(--auth-scheme KEY) for authenticated access.
The CLI reads plain text from the media URLs returned by the server, so the
machine running it needs network access to the API and the media host.
Annotations supply section structure and retrieval. Server-side semantic
search is optional. If the source lacks a plain-text extract, the engine uses
reconstructed annotation excerpts. An explicit null based on excerpts is
recorded as insufficient_document_text because absence is unverified.
Bundle mode replaces the API with a local JSON export containing fieldsets,
documents, text or text-file references, and annotations. Live and bundle
runs both use the configured model provider for inference. Use
--model test to exercise the pipeline with a local test model.
Command line
export OC_API_TOKEN=... # a JWT or an API key (--auth-scheme KEY)
# every document in a corpus
tabula-razer run --api-url https://contracts.example.com \
--fieldset 12 --corpus 4 --output-dir out/ --model openai:gpt-4o-mini
# specific documents (add --corpus to include that corpus's non-structural annotations)
tabula-razer run --api-url ... --fieldset 12 --document 101 --document 102 --output-dir out/
# the documents of an existing server extract (its fieldset is used unless --fieldset is given)
tabula-razer run --api-url ... --extract 31 --output-dir out/
# see what a fieldset will do before spending tokens
tabula-razer fieldset --api-url ... --fieldset 12
run prints the JSONL paths (one per extracted column) to stdout. Progress
and a summary go to stderr. IDs can be Relay global IDs or numeric primary
keys.
| Flag | Default | Meaning |
|---|---|---|
--model |
openai:gpt-4o-mini |
Any pydantic-ai model spec. test makes no LLM calls (plumbing check). openai:gpt-5.6* is routed to the Responses API automatically. |
--concurrency |
4 | Concurrent cells, and documents held in memory. |
--request-limit |
20 | Model requests allowed per cell. |
--full-text-char-limit |
24000 | Documents this short are inlined into the prompt. |
--no-semantic-search |
off | Drop the server-side semanticSearch tool; keyword search over annotations is always available. |
--no-grounding |
off | Skip locating extracted strings in the text. |
--include-llm-log |
off | Store each cell's full message history. |
--resume |
off | Keep completed / not_found lines in --output-dir and run the rest. |
--strict |
off | Exit 3 if any cell failed. |
From the repository root, run the bundled example with the local test model.
tabula-razer run --bundle tests/fixtures/nda_bundle.json \
--fieldset fs-nda --corpus corpus-ndas --output-dir out/ --model test
Outputs
Each runnable column gets a <column>.jsonl file with one
ExtractionRecord per resolved document. A row includes document and column
IDs, the typed value or failure details, source annotation IDs, grounding
spans, model usage, and timestamps. The file is flushed as each cell finishes,
so row order follows completion order.
{"schema_version": 1, "fieldset_id": "RmllbGRzZXRUeXBlOjEy", "column_id": "...",
"column_name": "Governing Law", "document_id": "...", "document_title": "Mutual NDA",
"status": "completed", "data": "the State of Delaware", "output_type": "str",
"extract_is_list": false,
"sources": ["QW5ub3RhdGlvblR5cGU6OTE="],
"grounding": [{"query_text": "the State of Delaware", "matched_text": "the State of Delaware",
"char_start": 1840, "char_end": 1861, "match_type": "exact", "match_quality": 1.0,
"annotation_ids": ["QW5ub3RhdGlvblR5cGU6OTE="]}],
"failure_mode": null, "error": null, "model": "openai:gpt-4o-mini",
"usage": {"requests": 3, "input_tokens": 5120, "output_tokens": 64},
"started_at": "...", "completed_at": "..."}
status: one ofcompleted: a value was extracted;not_found: the agent explicitly committed to "not in this document" (failure_mode: agent_committed_none);failed: no answer.failure_modesays why:- from the server's vocabulary:
usage_limit_exceeded,tool_loop_no_output,no_final_response; - added by this package:
invalid_output,invalid_column,document_load_failed,insufficient_document_text,exception.
- from the server's vocabulary:
sources: annotation IDs the agent's tools surfaced while answering. These are the citations, the same signal as the server'sDatacell.sources.grounding: where each extracted string sits in the document text, plus the most specific annotations containing it.
The manifest records the source and selection, model settings, document
count, each column's file name and status counts, and skipped columns. The
runner creates it before writing rows and sets finished_at when the run
finishes. --resume validates the source, fieldset definition, corpus,
extract, and resolved document set, then keeps settled rows and reruns the
rest. Start in a fresh directory if earlier output lacks a run identity.
The skipped_columns list covers manual-entry metadata columns, columns
with a custom server-side task_name, and columns with neither query nor
match_text.
GraphQL contract
The GraphQL adapter implements oc_extract.sources.DocumentSource using
these reads.
| Method | OpenContracts GraphQL field used |
|---|---|
get_fieldset |
fieldset(id) { fullColumnList } |
get_extract |
extract(id) { fieldset corpus fullDocumentList } |
list_documents |
corpus(id) { documents } (paginated) / document(id) (alias-batched) |
get_document_text |
document { txtExtractFile } (resolved at document load; storage requests use a separate client) |
get_annotations |
document { allAnnotations(corpusId:) { … parent { id } annotationLabel { … } } } |
semantic_search (optional) |
semanticSearch(documentId:, corpusId:) |
Custom DocumentSource adapters can feed the same runner. They implement
checkpoint_identity() to support resume.
Python API
from oc_extract import DocumentSelection, EngineConfig, OpenContractsGraphQLSource, run_extraction
async with OpenContractsGraphQLSource("https://contracts.example.com", token=token) as source:
result = await run_extraction(
source,
fieldset_id="12",
selection=DocumentSelection(corpus_id="4"),
output_dir="out",
config=EngineConfig(model="anthropic:claude-sonnet-5-5"),
)
result.files # [Path("out/effective-date.jsonl"), ...]
extract_column(DocumentContext, Column, ...) runs a single cell when you
need finer control.
Agent tools
| Tool | Purpose |
|---|---|
similarity_search |
Server-side vector search (when the source supports it) |
search_annotations |
IDF-weighted keyword search; filter by structural / label |
get_document_outline |
Section tree of structural annotations |
get_annotation |
One annotation with its ancestors and children |
get_subtree_text |
A section's full text from its heading |
list_annotation_labels |
Labels present, with counts |
load_document_text |
Raw text slices |
Development
pip install -e ".[test]"
python -m pytest
The tests make no network or LLM calls:
- the GraphQL client runs against a fake OpenContracts server using the checked-in SDL fixture;
- the agent runs on pydantic-ai's
FunctionModel/TestModel.
Set OC_GRAPHQL_SCHEMA to the path of an OpenContracts checkout's
config/graphql/schema.graphql to run the same tests against its full
GraphQL contract.
Publishing
PyPI Trusted Publishing uses project tabula-razer, GitHub owner
Open-Source-Legal, repository tabula-razer, workflow publish.yml,
and environment pypi.
Publish a GitHub release tagged with the package version prefixed by v,
such as v0.1.0b1. The workflow runs CI on that commit, builds and checks
the wheel and source distribution, then uploads them to PyPI using OIDC.
Run the workflow manually to build and validate the GitHub Actions artifact.
Metadata
Release files for tabula-razer 0.1.0b1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tabula_razer-0.1.0b1.tar.gz | 78.3 kB | With provenance | Details for tabula_razer-0.1.0b1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tabula_razer-0.1.0b1-py3-none-any.whl | Python 3 | none | any | Details for tabula_razer-0.1.0b1-py3-none-any.whl |
Total release size: 136.1 kB
Release files / tabula_razer-0.1.0b1.tar.gz
| Download URL | tabula_razer-0.1.0b1.tar.gz |
|---|---|
| Size | 78.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c010c13dc6a344ac5c1c9a7eed69581a9edbd5e5bcc0349f36154343d7ba5978
|
|
BLAKE2b-256 checksum How to use checksums |
4ee2dd93c7b58eda146a2aa4273d404884286b18bca812b11802381291d14735
|
| 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 29, 2026.
Transparency logRelease files / tabula_razer-0.1.0b1-py3-none-any.whl
| Download URL | tabula_razer-0.1.0b1-py3-none-any.whl |
|---|---|
| Size | 57.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dde7e8676700dd077de79cd1212ac4706cf6bb7cb74ee858d9b13ff816a1ec12
|
|
BLAKE2b-256 checksum How to use checksums |
fd7b7fd02305a4cbb038c6f9b460139d1e85d0e6ad4ab00fcfa3bb5a0fb7b510
|
| 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 29, 2026.
Transparency logSecurity for tabula-razer 0.1.0b1
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.
Attestation for tabula_razer-0.1.0b1.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 29, 2026.
Transparency logA 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.