Document-Wide AI Editing in Microsoft Word Add-In
harvey · Legal · 2025 · source Agentic: yes · promotional bias: med · source-backed · extracted with prompt 0.5.6 (schema v2)
Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.
Problem
Domain: Legal document-wide editing inside Microsoft Word
Harvey needed to edit entire long legal documents from one instruction while preserving Word document structure, avoiding long-context coverage gaps, and keeping legal edits consistent across many pages.
Constraints:
- Word documents are OOXML ZIP packages with interdependent XML parts, styles, numbering, tables, and content controls.
- LLMs perform worse when asked to both reason legally and emit valid OOXML.
- Legal documents can be hundreds of pages and single requests can require thousands of changes.
- One-shot long-context edits miss the middle of documents because of position bias.
- Evaluation required both automated directional signals and legal expert judgment.
Architecture
Harvey separates document engineering from model reasoning. It maps OOXML objects to a natural-language document representation, asks models to propose text-level edits, deterministically maps those edits back to OOXML mutations through the Word JavaScript object model, and uses an orchestrator-subagent architecture for full-document coverage. The orchestrator reads the whole document, decomposes work into bounded chunks, and gives subagents precise localized instructions plus global consistency constraints.
Diagram confidence: explicit (topology described by the source).
flowchart LR word-document["Word document"] --> ooxml-to-text-mapper["OOXML-to-text mapper"] ooxml-to-text-mapper --> orchestrator-model["Orchestrator model"] orchestrator-model --> subagent-editors["Subagent editors"] subagent-editors --> deterministic-ooxml-applier["Deterministic OOXML applier"] ooxml-to-text-mapper --> deterministic-ooxml-applier["Deterministic OOXML applier"] deterministic-ooxml-applier --> word-javascript-object-model["Word JavaScript object model"] word-javascript-object-model --> word-document["Word document"] evaluation-framework["Evaluation framework"] --> orchestrator-model evaluation-framework --> subagent-editors
Components
| Component | Role | Interacts with |
|---|---|---|
Word document |
OOXML-backed legal document with text, formatting, styles, tables, and relationships. | OOXML-to-text mapper |
OOXML-to-text mapper |
Creates a reversible natural-language representation of document structure/content. | Orchestrator model, Deterministic OOXML applier |
Orchestrator model |
Reads the whole document, plans the work, assigns bounded chunk tasks, and sets global constraints. | Subagent editors |
Subagent editors |
Apply precise localized edit instructions over bounded document chunks. | Deterministic OOXML applier |
Deterministic OOXML applier |
Translates text-level edits back into Word object model changes while preserving structure. | Word JavaScript object model |
Word JavaScript object model |
Applies edits through supported Word APIs rather than raw XML generation. | Word document |
Evaluation framework |
Automated and expert-led metrics for coverage, request alignment, and implementation experiments. | Orchestrator model, Subagent editors |
Data flow
A user gives a document-wide edit instruction in the Word Add-In. Harvey converts the OOXML-backed Word document into a reversible natural-language representation, the orchestrator plans and chunks the work, subagents edit localized sections, global constraints maintain consistency, and deterministic translation applies the edits back into Word while preserving styles, numbering, tables, and content controls.
Why this architecture
Harvey separates OOXML manipulation from legal reasoning because raw OOXML generation is verbose, interdependent, and brittle. It then uses orchestration and subagents because one-shot long-context editing under-edits the middle and is slower/costlier without guaranteeing recall.
Models used: Orchestrator model (unspecified) · Subagent models (unspecified) · Multi-model Harvey stack · Microsoft Word JavaScript API
Scale
- Users can edit 100+ page documents with a single query.“Users can edit 100+ page documents with a single query”article, stated
- A single legal edit request can require thousands of individual changes.“a single edit request can require thousands of individual changes.”article, stated
- The evaluation framework generated outputs over a large input set in less than five minutes.“enabled us to generate a full set of outputs over a large input set on our target experiment in less than five minutes.”article, stated
Alternatives considered (roads not taken)
Have models read and write OOXML directly
Rejected because: OOXML is verbose and interdependent, and constrained XML generation hurts reasoning quality and validity.
Use one-shot long-context editing over the whole document
Rejected because: Evaluations found it missed large portions of long documents and suffered from lost-in-the-middle effects.
Rely only on human expert evaluation
Rejected because: The number of experiments exceeded human evaluation capacity, so Harvey combined automated and expert-led evaluation.
Patterns
multi-agent-orchestration (agent)
An orchestrator model plans document-wide work and delegates bounded chunks to subagents.
context-compaction (context)
The system decomposes long legal documents into bounded chunks so subagents can focus on smaller contexts while the orchestrator maintains global constraints.
structured-output-contract (document-engineering)
The model proposes text-level edits that are deterministically mapped back into precise OOXML/Word mutations.
eval-driven-development (evaluation)
Harvey used automated and expert-led evaluation to compare model roles, tracked-change representations, and implementation approaches.
Tradeoffs
Separate legal reasoning from OOXML mutation
Chose Natural-language edit proposal plus deterministic OOXML application over Direct model-generated OOXML.
Rationale: This preserves Word structure and avoids forcing the model to reason and emit valid XML simultaneously.
Use orchestrator-subagent decomposition
Chose Global planner plus localized subagents over One monolithic long-context edit.
Rationale: Chunked subagents improve thoroughness and latency/cost behavior for document-wide changes.
Blend automated and expert-led evaluation
Chose Directional automated metrics plus lawyer expertise over Pure human review for every experiment.
Rationale: Human expert review alone could not keep up with the number of experiments.
Gotchas (what bit them)
Raw OOXML is a bad model interface for legal reasoning.
Root cause: OOXML is verbose, interdependent, and schema-sensitive while LLMs are trained primarily on natural language.
Resolution: Use a reversible natural-language representation and deterministic OOXML application.
Long-context models still under-edit the middle of legal documents.
Root cause: Position bias/lost-in-the-middle causes over-attention to beginning/end and partial coverage.
Resolution: Use orchestrator-subagent decomposition into bounded chunks.
Model-choice experimentation can exceed expert review capacity.
Root cause: A multi-model architecture creates many latency/cost/quality combinations to evaluate.
Resolution: Combine automated directional metrics with lawyer expert review.
Evaluation
Harvey used domain experts, product owners, and engineers to define quantitative and qualitative metrics, then generated automated directional signals and A/B experiments with legal expert collaboration.
Metrics: Percentage of body elements modified · Alignment with user request · No regression on previous dataset · Improvement on redline-referencing queries · Large input-set output generation under five minutes
Outcomes
- Enabled document-wide edits on 100+ page legal documents from a single query.
- Supported use cases such as checklist conformance, templates, and jurisdiction/client adaptation.
- Turned hours-long manual legal editing tasks into one-query interactions.
- Built an evaluation framework combining automated outputs and legal expertise.
The architecture targets 100+ page legal documents, 200-page M&A agreements, and edit requests that can require thousands of changes.