Skip to content

AI friendly edit functions #1568

Description

@eric-burel

Hey folks,

I've been experimenting for a few months with a CLI agent for administrative tasks, fais, which involves a lot of editing .docx. I find python-docx API nice to create new document, but not really fit for editing a document using AI.

The tricky part is to guarantee that the LLM doesn't destroy the XML structure. Naive implementations will have the model to output the whole document just to edit one text, but LLM like parrots can repeat thing with slight alterations. Which is why AI agent often struggle to edit documents without destroying the layout.

There are many agentic techniques that can fix this and allow for efficient and hallucination free edits. For instance I've implemented it like so:

Since the LLM doesn't repeat the XML, it can't alter it either (at worst, the selector is wrong and the edit fails, but it just can't wreak havok in your document).

So my point is: could python-docx or python-openxml org be home for a few additional methods that are fit for edits by an agentic AI system, such as opening the document as a selector map and such?

The alternative would be a separate project but I've always found that in open source, the more we are working on a project, the merrier :)

PS: I know that AI keyword can bring a lot of garbage and have a terrible effect on open source projects, so it might be worth a disclaimer: I do teach agentic AI to real developer and the code I share here is an handcrafted pattern that I designed on my own

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions