Behind the editor

Why is so good at editing documents?

A language model can write a fine sentence, but putting it back with formatting is a different job. We explain why it has been difficult to make AI edit a document, and what we built to fix it.

9 min readOctober 3, 2026

Overview

Ask a chatbot to fix a clause in a Word file and you are asking it to do two jobs at once: change the words, and rewrite the file format that holds them. Language models are good at the first job and unreliable at the second.

takes the second job away from the model. This article explains why that matters, how it works on long documents, and how it compares with chat websites and computer-use agents.

  1. 01A language model reads a document as markup, not as a page.
  2. 02One wrong character can make a file unreadable, and long outputs make wrong characters likely.
  3. 03 separates content from formatting: the model edits words, our code writes the file.
  4. 04Long documents are batched, split and given context, as modern coding agents do.
  5. 05Chat websites can edit files with Python, but changes can go missing silently.
  6. 06Computer-use agents edit like a human, at many times the cost.

01

LLM only sees text, not formatting

Open a contract in Word and you see a page: a heading in the house style, a bold amount, an underlined deadline. The Word program creates these formatting, so we can edit visually. Underneath a Word file (.docx) is a complex system of XML, where every word we see is painfully annotated with hidden words known as markup.12

What you see

What the model sees

<w:p>  <w:pPr><w:pStyle w:val="Heading2"/></w:pPr>  <w:r><w:t>4. Rent</w:t></w:r></w:p><w:p>  <w:pPr><w:jc w:val="both"/></w:pPr>  <w:r><w:t xml:space="preserve">The tenant shall pay </w:t></w:r>  <w:r><w:rPr><w:b/><w:color w:val="1F4E79"/></w:rPr><w:t>US$2,400</w:t></w:r>  <w:r><w:t xml:space="preserve"> on </w:t></w:r>  <w:r><w:rPr><w:i/><w:u w:val="single"/></w:rPr><w:t>the first day of each month</w:t></w:r>  <w:r><w:t>.</w:t></w:r></w:p>
Figure 1The same clause twice. The words take 68 characters; the XML around them takes 457. Excerpt of word/document.xml.

A LLM is not aided by Microsoft Word, LibreOffice or Pages and must rely on its own understanding of the markups. To edit correctly, a LLM needs to understand the effect of the original markup and write the new sentence in the correct markup.

02

LLM output is inherently unstable

Models may have improved substantially but even the latest still make mistakes. In a 2026 Microsoft Research study of 19 models across 52 professional domains, frontier models such as Gemini 3.1 Pro, Claude 4.6 Opus and GPT 5.4 corrupted an average of 25% of document content by the end of long editing workflows.4

In a Word file, one small error is enough to make a file unusable. Here the model has dropped a single slash:

<w:p>  <w:pPr><w:jc w:val="both"/></w:pPr>  <w:r><w:t xml:space="preserve">The tenant shall pay </w:t></w:r>  <w:r><w:rPr><w:b>1<w:color w:val="1F4E79"/></w:rPr><w:t>US$2,400</w:t></w:r>  <w:r><w:t xml:space="preserve"> on </w:t></w:r>  <w:r><w:rPr><w:i/><w:u w:val="single"/></w:rPr><w:t>the first day of each month</w:t></w:r>  <w:r><w:t>.</w:t></w:r></w:p>
Figure 2One missing slash leaves the bold tag open. The XML is no longer well-formed, and Word will not open the file normally.3

XML has no tolerance for bad markups. A file is either well-formed or it is not. Word can sometimes recover a broken file, but the recovered copy may be missing text or formatting.

Longer output, more mistakes

The risk grows with length. LongProc, a 2025 benchmark of long structured output, found open-weight models faltering at 2,000 output tokens and GPT-4o degrading significantly at 8,000.5 Another study found that performance drops by 13.9% to 85% as the input grows, even when the model can retrieve every relevant fact.6 A 10-page Word document is about 10,000 tokens, trying to edit all 10 pages at once without error is a moonshot.

<w:p>  <w:pPr><w:pStyle w:val="ClauseText"/></w:pPr>  <w:r><w:rPr><w:b/><w:sz w:val="24"/></w:rPr><w:t>5.1</w:t></w:r>  <w:r><w:rPr><w:sz w:val="24"/></w:rPr><w:t xml:space="preserve"> Harlow &1 Pike LLP acts for the Landlord in all matters arising under this Lease.</w:t></w:r></w:p><w:p>  <w:pPr><w:pStyle w:val="ClauseText"/></w:pPr>  <w:r><w:rPr><w:b/><w:sz w:val="24/>2</w:rPr><w:t>5.2</w:t></w:r>  <w:r><w:rPr><w:sz w:val="24"/></w:rPr><w:t xml:space="preserve"> The Tenant shall keep the Premises in good and substantial repair and condition.</w:t></w:r></w:p><w:p>  <w:pPr><w:pStyle w:val="ClauseText"/></w:pPr>  <w:r><w:rPr><w:b/><w:sz w:val="24"/></w:rPr><w:t>5.3</w:t></w:r>  <w:r><w:rPr><w:sz w:val="24"/></w:rPr><w:t xml:space="preserve"> Any notice must be given in writing and delivered to the address stated in Schedule 2.</w:t></w:p>3<w:p>  <w:pPr><w:pStyle w:val="ClauseText"/></w:pPr>  <w:r><w:rPr><w:b/><w:sz w:val="24"/></w:rPr><w:t>5.4</w:t></w:r>  <w:r><w:rPr><w:sz w:val="24"/></w:rPr><w:t xml:space="preserve"> The Landlord may terminate this Leas4
  1. 1A bare ampersand in the text. XML requires it to be escaped as an entity.
  2. 2A missing closing quote. Everything after it is read as part of the value.
  3. 3A run that is never closed before the paragraph ends.
  4. 4The output simply stops. Long generations can hit a length limit or time out mid-tag.
Figure 3Four clauses of model output, four kinds of failure. Each one alone makes the file unreadable.

03

How solves it

We write custom programs that separate formatting from content. The model receives the words it needs to change, together with a rendered image of the page, so it gets the assistance from a Word program. Our code then puts the edited words back into the original runs and leaves the rest of the file untouched.

Your file

<w:p>  <w:pPr><w:jc w:val="both"/></w:pPr>  <w:r><w:t xml:space="preserve">The tenant shall pay </w:t></w:r>  <w:r><w:rPr><w:b/><w:color w:val="1F4E79"/></w:rPr><w:t>US$2,400</w:t></w:r>  <w:r><w:t xml:space="preserve"> on </w:t></w:r>  <w:r><w:rPr><w:i/><w:u w:val="single"/></w:rPr><w:t>the first day of each month</w:t></w:r>  <w:r><w:t>.</w:t></w:r></w:p>

separates content from formatting

Extracted content

The tenant shall pay US$2,400 on the first day of each month.

Rendered page

Both go to the model

Language modelEdits words. Never touches XML.

The model returns edited content

Model output

The tenant shall pay US$2,400US$2,600 on the first day of each monththe fifth day of each month.

writes the words back into the original runs

Your file, edited

<w:p>  <w:pPr><w:jc w:val="both"/></w:pPr>  <w:r><w:t xml:space="preserve">The tenant shall pay </w:t></w:r>  <w:r><w:rPr><w:b/><w:color w:val="1F4E79"/></w:rPr><w:t>US$2,600</w:t></w:r>  <w:r><w:t xml:space="preserve"> on </w:t></w:r>  <w:r><w:rPr><w:i/><w:u w:val="single"/></w:rPr><w:t>the fifth day of each month</w:t></w:r>  <w:r><w:t>.</w:t></w:r></w:p>

✓ Valid .docx. Bold, colour and underline are exactly as they were.

Figure 4The edit pipeline, simplified. Highlighted text is the only part of the file that changed.

This solves both problems at once. The model now sees the formatting it could not see before, and it no longer writes the markup it was most likely to break.

You will not find this layer in a general-purpose chatbot. The extraction, rendering and reassembly programs are built and maintained by ’s own engineers.

04

Solving the long-context problem

Some edits are long: a paragraph that runs across several pages, or one change applied consistently across hundreds. For these we learned from software engineering. In March 2026, Anthropic accidentally published the source code of Claude Code, its AI coding agent, inside a public npm package.7

That leaked code editor teaches a plain lesson: to edit something long, break it down. We split a document into groups of pages, a technique called batching, and split long paragraphs into sentences, so each edit is small enough to get right.

Breaking a document apart creates a new problem: context. How do you edit a paragraph on page 60 using a definition on page 2? Here, two years of experience in AI code editor (Cursor, GitHub Copilot, OpenAI Codex) pays off. Their answer is context engineering, which gathers related information into a focused collection and give it to sub-agents with clean context windows.8 We do the same with documents. We group logically related information, as a careful reader would, then send it with the edit target to sub-editors that make the actual change.

1Batch the document

pp. 1–40pp. 41–80pp. 81–120pp. 121–160pp. 161–200pp. 201–240pp. 241–280pp. 281–300

2Split long paragraphs

Clause 18.3 · p. 60
Sentence 1Sentence 2Sentence 3Sentence 4Sentence 5

3Gather context, then edit in parallel

Defined termspp. 2–12

Parties and rolesp. 1

Earlier amendmentsp. 34

Sub-editor 1pp. 1–40 + collection

Sub-editor 2pp. 41–80 + collection

Sub-editor 3pp. 81–120 + collection

Figure 5A 300-page document, broken down. Each sub-editor gets a small piece of the document plus the context that piece depends on.

Example: redacting a judgment

A lawyer wants every witness name in a judgment redacted, and a list of the cases it cites for a junior to research.

  1. Search. finds every personal name and every case citation with ordinary pattern matching. No model is needed yet.
  2. Classify. Each name, with the sentence around it, goes to a model that decides: witness, lawyer or judge. The answers build a collection of witnesses.
  3. Collect. The same method builds a collection of cited cases.
  4. Act. Because we know exactly where each witness name was found, we redact those places, and only those, in the original file.

IN THE HIGH COURT OF JUSTICE

KING’S BENCH DIVISION

Harrow v Kestrel Logistics Ltd

Before: Mrs Justice Holloway

JUDGMENT

Mrs Justice Holloway: This claim arises from the collapse of a loading bay at the Defendant’s warehouse on 14 March 2024. The Claimant was represented by Ms Priya Raman and the Defendant by Mr Thomas Whitby. I heard oral evidence over four days.

The principal eyewitness, Mr Daniel Okafor, was a forklift operator on the night shift. Mr Okafor told the court that the warning lights on the bay had been out of order for several weeks, and that he had reported this twice. A second witness, Ms Margaret Ellison, a contractor who inspected the bay in February, confirmed that her report recommended immediate repair. I found both witnesses careful and credible.

An occupier’s duty of care to those lawfully on its premises is well established, and I take as my starting point the neighbour principle in Donoghue v Stevenson [1932] AC 562. Whether it is fair, just and reasonable to impose a duty in novel circumstances is governed by Caparo Industries plc v Dickman [1990] 2 AC 605, but these circumstances are not novel. Mr Whitby submitted that the losses claimed were too remote. That submission must be tested against Hadley v Baxendale (1854) 9 Exch 341.

Having considered the evidence of Mr Okafor and Ms Ellison alongside the documents, I am satisfied that the Defendant knew of the defect and failed to act. The claim succeeds on liability. Damages will be assessed at a further hearing. I am grateful to Ms Raman and Mr Whitby for their clear and focused submissions.

Figure 6Switch views to see the result. The judgment and names are fictional; the three cited cases are real.

05

Can chatgpt.com, claude.ai and other chat websites do the same?

Sometimes, yes. These websites often include a Python interpreter, which lets the model open a Word or PowerPoint file and edit its XML with code.

But the code is still written by an unstable model, and nothing checks the result against the original. In our internal testing, we often received documents with unexpected deletions and edits. In one extreme case, a 20-page document came back as 10 pages, with no warning.

Chat website with Python

20 pages
10 pages

Done! I’ve updated your document with the requested changes.

No mention of the 10 missing pages.

change log

  • p. 4 · Clause 2.1

    thirty (30) days sixty (60) days

    Revert
  • p. 9 · Clause 6.3

    the Supplier the Contractor

    Revert
  • p. 17 · Schedule 1

    US$2,400 US$2,600

    Revert

Generate new document

Figure 7Left: a silent truncation from our internal testing. Right: every AI change on OneTurn is listed and can be reverted.

A silent omission or modification is fatal for any serious work. On , every change our AI agent makes is recorded. You can review each one, revert any of them, and generate a new document.

06

Can computer-use agents like OpenClaw or Manus do this?

These agents control a computer the way a person does. They open the document in Microsoft Word or PowerPoint, then scroll, click and type.11 Because they use the same programs as a human, they can edit like a human, and the results are often impressive.

The price is cost and speed. The agent reads a document by taking screenshots as it scrolls, and every small step needs a model call to decide what to do next. A full-HD screenshot costs between about 1,500 and 2,700 tokens on its own.10 On the OSWorld benchmark, even the best agents took 2.7 to 4.3 times more steps than necessary, and later steps took up to 3 times longer than early ones.9

Computer-use agent

  1. Take a screenshot
  2. Model decides the next action
  3. Scroll, click or type
  4. Repeat for every step

  1. Read the text once
  2. Edit in batches
  3. Write the file
20-page contract, 30 editsComputer-use agent
Model calls≈ 180≈ 12
Tokens per call≈ 10,000≈ 4,000
Total tokens≈ 1,800,000≈ 48,000
Difference≈ 37× more, or ≈ 100–160× with the extra steps measured on OSWorld
Figure 8Assumptions: about 11,000 words; 60 screenshots to read the document; 4 actions per edit; each call carries a screenshot plus recent history. OneTurn reads the text once and sends edits in batches.

By our estimate, a computer-use agent can use up to 100 times more LLM tokens than for the same edits, and take far longer to finish.

Sources

  1. Structure of a WordprocessingML documentMicrosoft Learn · Open XML SDK documentation
  2. ECMA-376: Office Open XML file formatsEcma International · standard
  3. Validate a word processing documentMicrosoft Learn · Open XML SDK documentation
  4. LLMs Corrupt Your Documents When You DelegateLaban, Schnabel and Neville · Microsoft Research · 2026
  5. LongProc: Benchmarking Long-Context Language Models on Long Procedural GenerationYe et al. · COLM 2025
  6. Context Length Alone Hurts LLM Performance Despite Perfect RetrievalDu et al. · Findings of EMNLP 2025
  7. Anthropic Accidentally Exposes Claude Code Source via npm Source Map FileInfoQ · 7 April 2026
  8. Effective context engineering for AI agentsAnthropic Engineering · 29 September 2025
  9. OSWorld-Human: Benchmarking the Efficiency of Computer-Use AgentsAbhyankar, Qi and Zhang · MLSys 2026
  10. Vision: resolution and token costClaude Platform documentation
  11. Meta’s Manus launches desktop app to bring its AI agent onto personal devices amid OpenClaw crazeCNBC · 18 March 2026

Figures are illustrations made for this article. The XML is real WordprocessingML; file names, people and the judgment are fictional.

Try it on a document you cannot afford to break.

Try for free →