docling-project / docling-project/docling

Feature discussion: clause-level extraction with cross-reference resolution for legal documents

Open
#3,640 0 comments 0 reactions 0 assignees View on GitHub
triage/close-stale
Dominant language
Python
Stars
66.4k
Forks
4.8k
Avg merge
2d 21h
Merged PRs (30d)
84

Description

## Feature discussion: clause-level extraction with cross-reference detection for legal documents

First off — huge fan of docling. The layout-aware parsing is excellent for structured documents.

I've been building [AI Workdeck](https://github.com/zeweihan/aiworkdeck), an open-source AI workbench for legal/compliance document workflows, and we rely on docling-style document parsing as a foundation. One gap we keep hitting: **clause-level extraction with cross-reference resolution**.

### The problem

Legal contracts have dense internal cross-references — "as defined in Section 3.2(a)", "pursuant to Exhibit B", "the obligations set forth in Article 5". After parsing, these references become orphaned text because:

1. **Section numbering is layout-driven, not semantic**: docling captures headers/numbering visually, but "Section 3.2(a)" in body text isn't linked back to the parsed heading node.
2. **Cross-clause dependencies are invisible**: A termination clause referencing "Section 8" has a semantic dependency that's lost in flat chunk extraction.
3. **Definitions scatter**: "Capitalized Terms" defined in one section are used throughout — a definitions table is parsed structurally but not semantically linked to usages.

### What would help

A few ideas (not sure which fits docling's roadmap):

- **Named reference resolution**: Detect inline references like `Section X.Y` or `Exhibit Z` and emit them as typed links to the corresponding parsed element.
- **Definitions index**: Optionally extract a structured "defined terms" map from definitions sections.
- **Clause-level chunking mode**: Beyond page/char chunking, a mode that respects clause boundaries and preserves parent-section provenance.

### Our use case

We're using this for contract review where an LLM needs to verify consistency across clauses (e.g., "does the termination clause conflict with the renewal terms it references?"). Cross-reference awareness dramatically improves hallucination-prone retrieval.

Would love to hear if this is in scope, or if there's a recommended pattern others use. Happy to contribute a proof-of-concept for reference detection if there's interest.

Contributor guide

Open the contributing guide

Research direction

No files, tests, or entry points are named. Start by reviewing docling's existing parsed-element and chunking interfaces, then confirm with maintainers which of reference detection, definitions indexing, or clause-level chunking is in scope. Done would require an agreed scope and acceptance criteria before implementation begins.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
ai, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.