LLM-Assisted Contract Review: Technical Paths and Engineering Practices
This article outlines a deployable technical path for LLM-assisted contract review. It covers design goals, a six-layer system architecture, structure-preserving document parsing and clause segmentation, hybrid rule- and model-based risk identification with constrained structured outputs, and the generation of modification suggestions. The focus is on locating risks at the clause level, producing actionable replacement text, and writing suggestions back as native tracked changes and comments for human confirmation.
1. Background and Design Goals
Contract review is a high-frequency task involving both legal and business teams. A commercial contract typically contains dozens of clauses covering payment, delivery, breach, liability limitation, confidentiality, intellectual property, dispute resolution, and other dimensions. Manual review has three typical problems. First, review depth depends on individual experience, so similar clauses may be handled differently by different reviewers. Second, batch contracts can easily lead to omissions when the signing cycle is tight. Third, review comments are often circulated through text emails, and there is no traceable correspondence between suggested edits and the original text.
When introducing large language models into this process, the goal cannot stop at “letting the model read the contract and provide a summary.” A deployable system needs to meet three requirements: first, it must locate the specific clause and explain the source of the risk; second, it must output replacement text that can be adopted or edited directly; third, the modification results must be written back in the document’s native tracked-change and comment form for human confirmation clause by clause. The following sections break down the technical approach around these three requirements.
2. Overall Architecture
A complete contract review system is usually divided into six layers:
- Document access layer: receives common office document formats and extracts body text, heading levels, automatic numbering, tables, and header and footer information.
- Clause segmentation layer: splits the contract into the smallest semantic units that can be reviewed independently.
- Risk identification layer: uses a rule base and language models together to determine clause risk.
- Suggestion generation layer: generates replacement text and modification rationale for each risk item.
- Write-back layer: converts modification suggestions into tracked changes and comments in the document.
- Review and audit layer: records the input, output, and human decisions for each model call.
Data should be passed between layers in a structured form. If each layer repeatedly passes the entire contract text, the context length will grow quickly and problem localization will become difficult. Passing data by clause not only controls cost but also makes it easier to trace the source of each risk item.
3. Document Parsing and Clause Segmentation
The key in the parsing stage is to preserve structure. Extracting only plain text loses the numbering hierarchy, which causes subsequent segmentation errors and makes it impossible to locate the original paragraph during write-back. In practice, the following information should be preserved: the style level of the paragraph, the expanded result of automatic numbering, the row and column structure of tables, and the unique identifier of each paragraph in the document.
Clause segmentation often combines two strategies:
- Structural segmentation: defines boundaries based on numbering patterns such as “第X条,” “1.1,” and “(一).” Numbering conventions vary greatly across contracts, so a set of configurable matching rules needs to be maintained.
- Semantic segmentation: when a contract lacks standard numbering, adjacent paragraphs are merged according to topic similarity or keyword boundaries, and the maximum length of a single unit is limited to avoid excessively long input for a single review.
The following is a simplified example based on numbering patterns, assuming that paragraph text has already been extracted from the document:
import refrom dataclasses import dataclassCLAUSE_PATTERN = re.compile(r"^(第[一二三四五六七八九十百\d]+条|\d+(\.\d+)*)\s*")@dataclassclass Clause:clause_id: strtitle_line: strbody: strdef split_clauses(paragraphs: list[str]) -> list[Clause]:clauses: list[Clause] = []current: Clause | None = Nonefor text in paragraphs:text = text.strip()if not text:continuematch = CLAUSE_PATTERN.match(text)if match:if current:clauses.append(current)current = Clause(clause_id=match.group(1), title_line=text, body="")elif current:current.body += text + "\n"if current:clauses.append(current)return clauses
This example does not handle nested numbering or cross-page tables. In production, test cases for both cases need to be added.
4. Risk Identification: Hybrid Rules and Models
For risk identification, a hybrid strategy of “rules as the baseline and models as a supplement” is recommended.
The rule base is responsible for identifying high-frequency risks with clear boundaries, such as missing or clearly unbalanced liability caps, abnormal penalty ratios, unspecified payment deadlines, unclear dispute resolution clauses, ambiguous intellectual property ownership, missing confidentiality periods, and automatic renewal without a notice period. Rules have the advantages of fast judgment, interpretable results, and auditability, making them suitable as the baseline for review.
Language models are responsible for semantic issues that rules cannot cover, such as inconsistent use of defined terms within the same contract, implicit conflicts between clauses, and mismatches between the execution conditions of an obligation and the consequences of breach. Model output must be constrained to a fixed structure so that it can be parsed and subsequently validated by programs. The following is an example output for a risk item:
{"clause_id": "Article 8","risk_type": "liability_cap_missing","risk_level": "high","evidence": "Party B shall be liable for all losses caused by its breach of contract.","reason": "No compensation cap is set, and no distinction is made between direct and indirect losses, making the liability exposure difficult to estimate.","source": "model","confidence": 0.82}
The confidence field reported by the model should not be used directly as the basis for decisions. A more reliable approach is to use a human-labeled sample set to calculate the actual accuracy for different confidence intervals and then set thresholds accordingly. The source field is used to distinguish whether a risk item comes from rules or models, which facilitates post-hoc analysis of their respective contributions.
5. Suggestion Generation and Validation
Each risk item corresponds to one modification suggestion. The suggestion should include the original excerpt, the proposed replacement text, the modification rationale, and the source of the basis.
