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