Skip to content

Document Structure

Types produced by parse_structure(): deterministic parsing, no model calls.

DocumentStructure

DocumentStructure dataclass

Complete structural parse of a contract document.

This is the sole output of Layer 1. No LLM calls are made to produce any field on this object.

unresolved_refs: list[CrossReference] property

Cross-references that couldn't be mapped to a known section.

resolve_ref(raw_text: str) -> Section | None

Look up a section by its reference text.

Accepts forms like "Section 4.2(b)", "4.2(b)", "Article III", "§ 4.2". Returns the matching Section or None if not found.

get_section(number: str) -> Section | None

Direct lookup by normalised section number.

iter_all_sections() -> Iterator[Section]

Depth-first iteration over the entire section tree.

Section

Section dataclass

A single node in the contract's section hierarchy.

Numbering examples handled
  1. Numeric top-level 1.1 Numeric sub-section 4.1(a) Alpha-numeric 4.1(a)(i) Deep alpha-numeric Section 4 Named numeric Article III Roman-numeral top-level (a) Standalone lettered RECITALS Named block (no number)

full_ref: str property

Return the canonical section reference, e.g. 'Section 4.1(a)'.

iter_leaves() -> Iterator[Section]

Depth-first iteration over all leaf sections.

iter_all() -> Iterator[Section]

Depth-first iteration over self and all descendants.

DefinedTerm

DefinedTerm dataclass

A term formally defined within the contract.

Captured from both definition patterns
  1. Inline: "Confidential Information" means any information ...
  2. Parenthetical: ... (the "Disclosing Party") ...

CrossReference

CrossReference dataclass

A resolved or unresolved cross-reference found in the contract text.

parse_structure

ContractStructureParser

Parse a contract's plain text into a DocumentStructure.

Usage::

from contractex.structure import parse_structure
from contractex.loaders import load

doc = load("agreement.pdf")
structure = parse_structure(doc.full_text)

parse(text: str) -> DocumentStructure

Parse text and return a complete DocumentStructure.

Parameters:

Name Type Description Default
text str

Full plain-text content of the contract document.

required

Returns:

Type Description
DocumentStructure

DocumentStructure with section tree, defined terms, cross-refs,

DocumentStructure

schedules, recitals, governing-law hint, and any parse warnings.