Skip to main content

langchain-adeu

PyPI version License: MIT

LangChain integration for Adeu — Track Changes for Microsoft Word (.docx) in the LLM Era.

This package wraps the local, cross-platform, and offline-capable subset of Adeu's document-editing engine as native LangChain tools. It enables LangChain and LangGraph agents to read, edit, diff, sanitize, and finalize Microsoft Word documents while preserving the underlying formatting, layout, custom styles, and XML structures.


Installation

Install the package via pip or uv:

Using pip

pip install langchain-adeu

Using uv

uv add langchain-adeu

Quick Start

Instantiate the AdeuToolkit and register its tools with a tool-calling chat model. This short example initializes an agent capable of managing docx operations.

from langchain.agents import create_agent
from langchain_openai import ChatOpenAI
from langchain_adeu import AdeuToolkit

# Load a tool-calling model
model = ChatOpenAI(model="anthropic:claude-sonnet-4-6")

# Initialize the toolkit
toolkit = AdeuToolkit()
tools = toolkit.get_tools()

# Create the agent
agent = create_agent(model=model, tools=tools)

Worked Example: Multi-Tool Review & Redline Flow

Below is a complete, runnable workflow illustrating how an agent can read an existing draft, apply tracked changes, generate a visual diff, and sanitize metadata before sending it to a counterparty.

from langchain_adeu import AdeuToolkit

# 1. Instantiate the toolkit
tools_map = {t.name: t for t in AdeuToolkit().get_tools()}

read_tool = tools_map["adeu_read_docx"]
apply_tool = tools_map["adeu_apply_changes"]
diff_tool = tools_map["adeu_diff_docx"]
sanitize_tool = tools_map["adeu_sanitize_docx"]

input_path = "MSA_draft.docx"
redline_path = "MSA_redlined.docx"
clean_path = "MSA_final.docx"

# 2. Read the document to extract text with active tracked changes & comments
# clean_view=False ensures the LLM sees inline CriticMarkup (e.g. {++inserted++})
read_result = read_tool.invoke(
    {
        "reasoning": "Reading the draft to review tracked changes and comments.",
        "file_path": input_path,
        "clean_view": False,
        "mode": "full",
        "page": 1,
    }
)
print("--- Document Contents ---\n", read_result)

# 3. Apply a batch of edits (tracked modifications + a comment reply)
apply_result = apply_tool.invoke(
    {
        "reasoning": "Applying jurisdiction edits and replying to a comment.",
        "file_path": input_path,
        "author_name": "AI Reviewer",
        "output_path": redline_path,
        "changes": [
            {
                "type": "modify",
                "target_text": "Governing Law shall be the State of New York.",
                "new_text": "Governing Law shall be the State of Delaware.",
                "comment": "Updating jurisdiction to corporate standard.",
            },
            {
                "type": "reply",
                "target_id": "Com:1",
                "text": "Agreed. Applied jurisdiction change.",
            },
        ],
    }
)
print("\n--- Changes Applied ---\n", apply_result)

# 4. Generate a word-level diff to verify edits
diff_result = diff_tool.invoke(
    {
        "reasoning": "Verifying the applied edits with a word-level diff.",
        "original_path": input_path,
        "modified_path": redline_path,
        "compare_clean": True,
    }
)
print("\n--- Word-Level Diff ---\n", diff_result)

# 5. Sanitize document properties and remove author history for final delivery
# keep_markup=True preserves unresolved track changes while stripping metadata
sanitize_result = sanitize_tool.invoke(
    {
        "reasoning": "Stripping metadata before delivering the redline.",
        "file_path": redline_path,
        "output_path": clean_path,
        "keep_markup": True,
        "author": "Anonymous Advisor",
    }
)
print("\n--- Sanitization Report ---\n", sanitize_result)

Reading Large Documents & Navigation Ladder

When working with long documents (e.g. 50+ pages), avoid loading the entire text into the LLM context at once. Follow this progressive navigation ladder:

  1. Plan structure (mode="outline"): Inspect document hierarchy (headings, sections, tables) with optional depth limits via outline_max_level and detailed metadata with outline_verbose=True.
  2. Read by slice (page=N or page="2-6"): Load targeted page ranges or specific sections rather than the full document (page="all"). When page="all" exceeds the response budget, adeu_read_docx serves the first pages that fit plus an L1 outline and continuation hint; pass force=True to return the entire document in one call.
  3. Locate exact clauses (search_query): Find specific terms or phrases with pagination support (max_matches, match_offset), page-range filtering (page="4-5"), regex support (search_regex=True), case sensitivity (search_case_sensitive=True), and full-paragraph context (full_paragraph=True).
  4. Collect tracked-change IDs (mode="changes") & form fields (mode="fields"): Retrieve the ledger of active revisions and comment threads with fresh IDs (filtered optionally by changes_author or paginated via changes_offset) before executing accept, reject, or reply operations, or list content controls (CC:<N>) via mode="fields" (fields_offset) before set_field.

Transactional vs. Partial Edits & Sanitization Safety

  • Salvage vs. Transactional Edits (partial): By default (partial=True), adeu_apply_changes operates in salvage mode: valid edits are committed and saved while failing ones are recorded in the artifact and PARTIAL: report header for correction. Setting partial=False enables strict all-or-nothing transactional semantics where any validation failure rejects the entire batch and writes no output file.
  • Sanitization Refusal Safety (status="blocked"): adeu_sanitize_docx returns status="blocked" with an explanatory report instead of raising a tool error when a SanitizeError is encountered (e.g., attempting a full sanitize of a document with unresolved tracked changes without accept_all=True or keep_markup=True, or comparing against a low-similarity baseline without allow_low_similarity_baseline=True), aborting without modifying or writing an output file.
  • Text-Revision Verification Gate (success=False): adeu_apply_text_revision re-reads the applied document's clean text and compares it against the text you supplied. On a mismatch (e.g. headings or table cells that cannot be deleted via text replacement) it returns success=False with status="verification_failed", writes nothing to output_path, and keeps a <stem>.unverified.docx diagnostic copy at unverified_output_path — that copy is not the requested document. The artifact also relays the engine's own post-gate stats, so edits_skipped, the per-edit edits reports (each marked status="failed") and verification_error describe exactly what was attempted. A revision that would delete the majority of the document is refused the same way (status="error") unless allow_major_deletions=True.

Per-Tool Reference

Tool Name Purpose / When to Use Key Input Parameters Response Format / Output Shape
adeu_read_docx Reads a .docx file into Markdown. Use clean_view=False to audit active track-changes, or inspect document structure with specialized modes and search. file_path (str), clean_view (bool), mode ("full", "outline", "appendix", "changes", "fields"), page (int, str e.g. '2-6', 'all'), force (bool), no_chrome (bool), outline_max_level (int), outline_verbose (bool), search_query (str), search_regex (bool), search_case_sensitive (bool), max_matches (int), match_offset (int), full_paragraph (bool), changes_author (str), changes_offset (int), fields_offset (int) content_and_artifact (Returns projected Markdown text + structured metadata artifact)
adeu_apply_changes Commits a batch of edits (modify, set_field, accept, reject, reply, insert_row, delete_row) as native track-changes and comment threads. Operates in salvage mode by default (partial=True); set partial=False for strict transactional semantics. markup_mode="manual" writes strikethrough/underline formatting with comments instead of tracked revisions. file_path (str), author_name (str), changes (list[dict]), output_path (str), partial (bool), markup_mode ("track_changes", "manual"), ignore_control_locks (bool), ignore_document_protection (bool), allow_untracked_writes (bool) content_and_artifact (Returns completion text + structured change stats including minted IDs, actions, and document_state)
adeu_apply_text_revision Rewrites a whole document from revised clean text: Adeu diffs your text against the document's clean view and writes the delta as tracked changes. Use when handing back the entire edited text is easier than enumerating edits. revised_text must cover the ENTIRE document — anything omitted becomes a tracked deletion — and must contain no CriticMarkup. file_path (str), revised_text (str), output_path (str), author (str), allow_major_deletions (bool) content_and_artifact (Returns completion text + artifact with success, verified, edits_applied, status; on refusal success=False with status="verification_failed" — plus unverified_output_path — or status="error", and no output file)
adeu_diff_docx Generates a word-level patch, unified diff, or structured changes JSON showing insertions and deletions between two files. With output_path, also writes the comparison as a tracked-changes .docx of original_path in one step (all or nothing; never over an input). original_path (str), modified_path (str), compare_clean (bool), diff_format ("word_patch", "unified", "structured_changes"), output_path (str), author_name (str) content (Returns free-form @@ Word Patch @@ visual text, a unified diff, or — for "structured_changes" — a JSON object {"changes": [...DocumentChange], "warnings": [...]} that can be passed straight to adeu_apply_changes)
adeu_accept_all_changes Resolves and bakes all tracked changes and format modifications into plain text. Optionally removes comments. file_path (str), output_path (str), remove_comments (bool) content_and_artifact (Returns completion text + artifact mapping paths)
adeu_sanitize_docx Cleans document properties (author names, RSIDs, Custom XML, DMS traces). Validates against an optional baseline document. file_path (str), output_path (str), keep_markup (bool), baseline_path (str), author (str), accept_all (bool), allow_low_similarity_baseline (bool) content_and_artifact (Returns human-readable report text + structured cleanup stats)

What's NOT Included

This package intentionally focuses on local, cross-platform, offline-capable workflows. For the following, use the Adeu MCP server directly:

  • Live MS Word Interop (Windows COM) — real-time edits on an active Microsoft Word canvas.
  • Adeu Cloud Features — email fetching, multi-document asynchronous semantic validation.
  • MCP Apps UI — interactive Markdown preview rendering inside custom client interfaces.

Development & Testing

We use uv for dependency management and workspace isolation.

Installation

Sync development and testing dependencies locally:

make install

Running Tests

To run unit tests (isolated, socket-disabled):

make test

To run integration tests (requires real fixture .docx documents):

make integration_test

Code Formatting & Linting

We enforce Ruff for formatting and linting:

make format
make lint

License

MIT. See LICENSE.

Metadata

Release files for langchain-adeu 4.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-adeu 4.0.0
File Size Uploaded Provenance Actions
langchain_adeu-4.0.0.tar.gz 171.5 kB With provenance Details for langchain_adeu-4.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for langchain-adeu 4.0.0
File Interpreter ABI Platform Actions
langchain_adeu-4.0.0-py3-none-any.whl Python 3 none any Details for langchain_adeu-4.0.0-py3-none-any.whl

Total release size: 209.7 kB

Release files / langchain_adeu-4.0.0.tar.gz

Download URL langchain_adeu-4.0.0.tar.gz
Size 171.5 kB
Tags Source
SHA-256 checksum
How to use checksums
96e2abf0185d10482497cedb0ff3229879ae78554a4c3a5a114745d729d4c594
BLAKE2b-256 checksum
How to use checksums
9bcce14303a73809bc084eb4b1d4ceeab79d2ba35741b9e4422af37306c8ca83
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 13, 2026.

Transparency log

Release files / langchain_adeu-4.0.0-py3-none-any.whl

Download URL langchain_adeu-4.0.0-py3-none-any.whl
Size 38.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b60dc9857544e6fa29422b2c61f747159d65b269003e3f7a623de0d5439c539a
BLAKE2b-256 checksum
How to use checksums
611b737bf48ce5f43553092952edff08e62c0705c96933dbd99da375e5f4496d
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 13, 2026.

Transparency log

Security for langchain-adeu 4.0.0

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.

Select from 2 files

Attestation for langchain_adeu-4.0.0.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 13, 2026.

Transparency log

A 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.

Release history Release notifications | RSS feed

This release

4.0.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page