Products Technologies Demo Docs Blog Support Company

Private AI-Assisted DOCX Editing with RAG in ASP.NET Core

This article walks through a hands-on test of private AI-assisted DOCX editing with the TX Text Control AI preview in an ASP.NET Core sample. The document agent uses a local language model to review a mutual NDA against an approved clause policy retrieved from a private RAG collection. It identifies the deviations, and the TX Text Control engine applies the approved wording to the Word document.

Private AI-Assisted DOCX Editing with RAG in ASP.NET Core

General-purpose language models are familiar with common legal and business practices. However, they lack knowledge of an organization's internal rules, such as the approved confidentiality period for its NDAs or the precise wording its policies require. As explained in Building Legal Document AI with TX Text Control, private retrieval-augmented generation (RAG) can address this limitation by providing the model with relevant passages from approved internal documents, which stay on infrastructure you control.

In document workflows, private RAG can help the AI review documents, answer questions about the content, and propose edits that follow internal standards. Typical use cases include:

  • Legal: compare contracts with clause libraries and negotiation playbooks.
  • Healthcare: check documentation against internal procedures and approved templates.
  • Insurance and finance: draft responses based on the applicable policy wording.
  • HR: answer questions from current handbooks and expense policies.

These are often confidential documents that must not leave the organization's own systems. This article shows how private AI-assisted DOCX editing with RAG works in TX Text Control AI. The test uses the WebDocumentAssistant sample for ASP.NET Core, where the document agent checks an NDA against an approved clause policy and then, at the user's request, replaces a deviating clause with the approved wording.

What Is Private AI-Assisted DOCX Editing?

Private AI-assisted DOCX editing means an AI assistant reviews Word documents and proposes edits directly in your application, while inference and document data stay within your own infrastructure. A local language model interprets the user's request, private RAG supplies approved content, and the document engine applies the change to the DOCX. Unlike end-user tools such as Microsoft Copilot in Word, this article covers AI DOCX editing that developers build into their own applications.

Running AI locally does not make an application secure or compliant on its own. Authentication, authorization, encrypted transport, and logging are still required. A fully isolated deployment also needs self-hosted web assets and controlled outbound network traffic.

How Private AI-Assisted DOCX Editing Works

The document agent handles each request in four steps:

  1. The user types a request.
  2. The local model interprets the request and proposes structured tool calls.
  3. The TX Text Control AI integration sends those calls to the MCP document server.
  4. The TX Text Control engine performs the edit, and the updated document loads back into the editor.

Private AI-assisted DOCX editing workflow

The model never writes the DOCX file itself. It decides what should change, and the deterministic TX Text Control document engine performs the operation. The article LLM Tool Calling vs. LLM-Generated Files in .NET explains why this separation makes document AI more reliable.

Local Test Setup with TX Text Control AI

Component Configuration
Application WebDocumentAssistant sample, TX Text Control AI 0.1.0-beta.3
Chat model Qwen_Qwen3.5-4B-Q4_K_M (GGUF), 65536-token context
Hardware Developer PC, CPU only
Document engine TX Text Control MCP document server, running locally
Retrieval Keyword search, no embedding model
Test documents A fictional NDA and a fictional approved clause policy, both DOCX

To repeat the test, download the two test documents and run the WebDocumentAssistant sample from the TX Text Control AI samples repository on GitHub.

Run the WebDocumentAssistant Sample in ASP.NET Core

For complete setup instructions, including licensing, NuGet feed access, and the MCP administration password, see the Explore the Samples section of the TX Text Control AI article. The core steps start with cloning and building the sample repository:

git clone https://github.com/TextControl/txtextcontrol-ai-samples.git 
cd txtextcontrol-ai-samples 
dotnet restore TXTextControl.AI.Samples.sln 
dotnet build TXTextControl.AI.Samples.sln -c Release --no-restore

Place a compatible GGUF model in samples/WebDocumentAssistant/Models. Then start the MCP document server and, in a second terminal, the WebDocumentAssistant sample:

# Terminal 1: start the MCP document server
dotnet run --project samples/McpServer

# Terminal 2: start the WebDocumentAssistant sample
dotnet run --project samples/WebDocumentAssistant

The MCP document server listens on http://127.0.0.1:5000, and the sample runs at http://localhost:5187.

WebDocumentAssistant sample with a DOCX loaded in Document Studio

Using RAG to Review and Edit DOCX Documents

The test uses a fictional NDA that contains four deliberate deviations from a fictional clause policy, plus one clause that complies.

Step 1: Index the Approved Documents

First, add the approved clause policy to a private collection in the Knowledge tab.

Create the collection and add the NDA policy:

  1. Enter "Approved NDA Policies" as the collection name and click Create collection.
  2. Select the collection in the Collection dropdown.
  3. Under Reference documents, choose Approved-NDA-Clause-Policy.docx. The file is queued for local indexing.
  4. Click Refresh jobs and sources until the Indexing activity shows the file as Complete (100%).

Search the NDA policy to check the indexing (Preview evidence):

  1. Under Question, enter: What is the approved confidentiality period?
  2. Leave Retrieval mode on Automatic.
  3. Click Search references.

Result: The search returned five passages in keyword mode. The top results were the confidentiality rule and the approved three-year wording.

Indexed clause policy in the Knowledge tab

Keyword search worked immediately, with no embedding model required. For semantic search, a separate embedding model can be configured in the global knowledge settings.

Step 2: Compare the NDA with the Clause Policy

Before running the comparison, configure the knowledge settings in the toolbar:

  1. Reference knowledge: Select the collection created in Step 1, "Approved NDA Policies".
  2. Approved source: Keep the default, "All active sources".
  3. Allow explicitly requested document changes: Leave this option unchecked. This keeps the AI in read-only mode, so it can read the NDA but cannot modify it.

Next, the following prompt was sent to the document agent:

AI PromptCompare this NDA with our approved clause policy. List each deviation, the approved wording, and the source. Do not change the document.

The document agent returned a deviation analysis, listing the current wording, deviation, approved wording, and the policy source:

Clause Deviation in the NDA Found by the AI
Confidentiality period 7 years instead of 3 Yes ✅
Termination 60 days' notice instead of 30 Yes ✅
Governing law New York instead of Germany, courts of Bremen Yes ✅
Return of information 90 days instead of 30, no mention of written confirmation No ❌

Three of the four deviations were identified. The permitted disclosure clause, which matches the policy, was not flagged.

The full answer can also be downloaded as a PDF, which gives the reviewer a copy of the analysis to save or share.

NDA deviation analysis

Step 3: Review Individual Clauses

To review the return of information clause, which was missed in Step 2, the following clause-specific prompt was sent to the document agent:

AI PromptCompare the Return or Destruction of Information clause with our approved policy.

This time, the document agent found all three differences in the clause:

Clause element Deviation in the NDA Found by the AI
Return period 90 days instead of 30 Yes ✅
Trigger No "upon written request" provision Yes ✅
Written confirmation No mention of written confirmation Yes ✅

It quoted the approved wording from the policy and recommended updating the clause to match it.

Clause-level deviation analysis

In this test, the full-document comparison provided a useful overview but missed one deviation, while the clause-level question identified every difference in that clause, producing more accurate results. Even with AI assistance, a human review is still recommended before a contract is finalized.

Step 4: Update Clauses with Approved Policy Wording

To apply the approved wording, enable Allow explicitly requested document changes in the toolbar and send the request to the document agent:

AI PromptReplace the body text of the Return or Destruction of Information clause with the approved clause policy. Keep the heading and formatting unchanged.

The document agent replaced the clause with all three approved elements: the 30-day period, the "upon written request" trigger, and the written confirmation. The heading and formatting stayed unchanged. The remaining deviations can be updated the same way, one clause at a time, for more reliable results.

Clause updated by the TX Text Control engine

Performance and Preview Considerations

  • Expect latency on CPU. A 4B model on a CPU-only developer PC handled the review and the edits, but each request took about 40 to 150 seconds. A GPU or a central GPU server inside the company network reduces this.
  • Preview status. TX Text Control AI is a preview on NuGet, and APIs and behavior may change. A compatible GGUF model must be provided separately. An appropriate TX Text Control license is also required.

Learn More

Frequently Asked Questions

AI-assisted DOCX editing adds an AI document agent to the document editor in an application, so users can review and edit Word documents with natural-language instructions. The agent interprets each instruction and proposes changes, and a document engine applies them to the DOCX. The updated document then appears in the editor for the user to review.

Retrieval-augmented generation (RAG) lets an AI answer from your own documents rather than relying solely on its training data. With private RAG, documents such as an approved clause policy are indexed in a knowledge collection. The AI retrieves the relevant passages and uses them to answer or compare, while the reference documents remain on the organization's own systems.

Yes. TX Text Control AI runs with a local GGUF language model on a workstation, a private server, or a GPU server inside the company network. In a hands-on test, the model, the knowledge collection, the MCP document server, and the web app all ran on one CPU-only developer machine. No document, prompt, or retrieved passage was sent to a cloud AI service.

Add the TX Text Control AI NuGet packages to the application, provide a local GGUF model, and connect the TX Text Control MCP document server. The TXTextControl.AI.AspNetCore package provides the AI endpoints and browser libraries. The WebDocumentAssistant sample on GitHub shows the complete setup.

Yes, with private RAG. In a hands-on test, the document agent compared a mutual NDA with an approved clause policy and listed the deviations it found, with the approved wording and its source paragraph. Approval of the document remains with a human reviewer.

In a test with a mutual NDA and an approved clause policy, a 4B model on CPU found three of the four deviations in a full-document comparison. A clause-level question then found all three differences in the clause it had missed. Clause-level questions provided more accurate answers.

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Related Posts

ASP.NETAIASP.NET Core

Introducing TX Text Control AI: Private AI for Real Document Workflows in…

Today, we are excited to introduce the TX Text Control AI Preview, a suite of six NuGet packages and ten sample applications that integrate local generative AI, private knowledge retrieval, and TX…


ReactASP.NET CoreDOCX Editor

React DOCX Editor: Add Word-Like Editing to Your Web App

This tutorial shows how to add a React DOCX editor to your web application with TX Text Control .NET Server. It covers setting up the backend, adding the Document Editor component, and loading and…


JavaScriptASP.NET CoreDOCX Editor

How to Embed a DOCX Editor in a Web Application (ASP.NET Core)

This tutorial shows how to embed a DOCX editor in an ASP.NET Core web application with TX Text Control. It covers setting up the editor, loading a DOCX document, and editing it with true WYSIWYG…


AngularJavaScriptReact

DOCX Editor SDK: A Complete Evaluation Guide and Checklist

The right DOCX Editor SDK brings Microsoft Word-like editing into your web application and fits your technical and business requirements. This guide covers the capabilities and business…


ASP.NETASP.NET CoreMCP

Reliable Document AI in .NET: LLM Tool Calling vs. LLM-Generated Files

Reliable document AI needs a deterministic engine. With LLM tool calling, the LLM decides what the document should contain, and TX Text Control generates the file.

Share this blog post on:

​​​