Generating a new slide deck is the easy half of the problem. The harder half is the deck that already exists: last quarter’s board pack, built on a corporate template, with a grouped footer, a theme someone paid a designer for, a SmartArt diagram on slide 12 and speaker notes on most slides. When someone asks Summa to “update the figures on slide 4 and add a comparison slide after it”, the result has to be that same deck with two changes, not a lookalike.
This essay describes how we built that, what it costs, and where it still falls short.
What goes wrong when you do the obvious thing
A .pptx file is a zip archive of XML parts tied together by relationships. Libraries such as python-pptx, which we use, give you an object model over the parts they understand. The parts they don’t understand are simply carried along. Most of the damage a naive editor does comes from that gap between “what the library models” and “what is in the file”.
Four examples:
- Text replacement that misses the one thing asked for. Templates very often group the footer with a rule and a page number. A search-and-replace over a slide’s top-level shapes never looks inside the group, so “change CONFIDENTIAL to INTERNAL” changes everything except the footer.
- Rewriting a paragraph flattens it. Assigning new text to a whole paragraph is simpler than editing it run by run, and it turns every bold word into the style of the first run.
- Duplicating a slide loses its pictures. python-pptx has no duplicate operation. Deep-copying the shape XML onto a new slide looks right in the XML, but every image reference still points at a relationship that belongs to the source slide, so the copy opens with missing pictures.
- Changing the page size leaves the layouts behind. Setting a 16:9 width on a deck whose masters were drawn for a ten-inch page produces titles and body boxes hugging the left of every slide, with dead space down the right. The file is valid. It just looks wrong.
None of these raises an error. That is the real problem: the failures that matter are the ones where the deck saves, reopens and has quietly lost or broken something.
There is no server-side PowerPoint
For a spreadsheet in OneDrive or SharePoint, Microsoft Graph offers a workbook API that changes cells on the live file. There is no equivalent for presentations. Microsoft’s rich PowerPoint object model is Office.js, which only runs inside a PowerPoint add-in. So for a connected .pptx, downloading the file, editing it ourselves and uploading it back is not a shortcut; it is the only route available.
That makes the edit a read-modify-write, with a familiar failure: a colleague saves mid-edit, and our upload overwrites their work. Summa reads the file’s eTag immediately before the download and sends it back with the upload as an If-Match precondition. If anything was saved in between, Graph answers with a 412, and Summa reports a version conflict instead of replacing newer content with bytes computed from older content. The person is told; nothing is lost silently.
Native Google Slides is the exception: Google has a real server-side API (presentations.batchUpdate), so a native Google deck is edited where it lives. Every .pptx, wherever it is stored, goes through one engine of our own, which is pure: bytes in, bytes out.
The fidelity standard
We wrote the standard down at the top of the fidelity tests:
“It produced valid XML” is not the standard; “the parts nobody asked about are still there” is.
In practice that means a handful of rules, each backed by a test:
- Groups are walked, not skipped. Text replacement descends into group shapes, so the grouped footer changes and the page number beside it, in its own run, does not.
- Text is replaced run by run. Each run keeps its own formatting. The cost is that a match cannot span a run boundary, which is the right trade for the placeholder text this exists for.
- Unknown parts survive. SmartArt, embedded objects and animations live in package parts the engine has no model for. A test attaches such a part through a proper relationship and checks that it is still in the package, byte for byte, after an unrelated edit.
- The theme is never rewritten. A restyle changes runs, not the design the deck inherits; the test compares every
ppt/theme/part before and after. - Duplicates are self-contained. When a slide is copied, every relationship its shapes reference is re-created on the new slide, so the copy owns its own pictures.
And one rule sits above the rest: a deck that will not reopen is never returned. Saving successfully is not evidence the result is a presentation, so the engine loads what it wrote before handing it back.
def _save(presentation: Presentation) -> bytes:
output = io.BytesIO()
try:
presentation.save(output)
except Exception as exc:
raise PresentationError("presentation_save_failed", "The edited presentation could not be saved.") from exc
result = output.getvalue()
# Reopen what was written. A deck that saves and will not load again is the
# failure worth catching here: the caller is about to replace somebody's
# original with these bytes.
load_presentation(result)
return result
Edits are also all-or-nothing. A plan of operations is applied in order to an in-memory copy, and nothing is written anywhere until the save and reopen succeed. If the third of five operations fails, the original is untouched.
Honest about what it cannot do
Some things the engine refuses rather than attempts, because a quiet partial success is worse than a clear no.
When the model inspects a slide, each element carries an editable flag. Groups, media and anything the engine does not recognise are reported as not editable, and an attempt to restyle a group fails with “That element does not hold text” rather than appearing to succeed and changing nothing. A table can be rewritten in place only if the replacement has the same number of rows and columns, since the library cannot add or remove rows on an existing table and writing into whichever cells happen to line up would leave stale data in the rest. Macro-enabled decks are refused outright instead of having their VBA stripped: handing back a file that no longer works is worse than saying the format is unsupported.
Semantic slides on someone else’s template
New slides are described semantically. The model says a slide is a comparison with two columns, or a metric with a value and a label, and the engine decides where things go. Twelve such types exist, from title and section to chart, quote and closing.
A customer’s template does not have layouts called comparison. It has whatever its designer named them. So each semantic type maps to a short list of candidate layout names, best first, matched case-insensitively against the layouts the template actually contains:
"two_column": ("two content", "two column", "comparison"),
"comparison": ("comparison", "two content", "two column"),
"image_focus": ("title only", "blank", "picture with caption"),
An exact name match wins; failing that, a layout whose name contains a candidate; failing that, a blank or title-only layout, so an unrecognised template still produces usable slides. Only five types fill the layout’s own placeholders. The rest, such as a metric or a pull quote, are drawn as text boxes at proportions derived from the page, because a placeholder the template lacks cannot be filled, and consistent alignment is arithmetic a model should not be asked to do.
When a template is used for a new deck, its theme, masters and layouts do the design work and its own sample slides are removed. A test builds a deck on a template whose layouts are called things like “Acme Compare” and checks that the slides land on Acme layouts, that the sample slides are gone, and that the master’s footer survives.
Refuse, and say where it goes
A slide that cannot show a field should not silently drop it. A comparison slide shows only its two columns, so top-level bullets on it would vanish. Rather than render a slide that is quietly missing content, validation rejects it with an instruction the model can act on: “put the bullets in a column’s ‘bullets’”. A chart slide without a chart is refused, because it is not a slide with a small mistake; it is a blank page in the middle of someone’s deck. Bullets on a quote, image_focus, table or chart slide are refused with “put them on a slide of their own”.
Letting the model look
Even with all of this, a structural edit can be correct and still ruin a slide. The comment at the top of visual.py puts it plainly: “A structural edit that reads perfectly in XML — replacing a six-word title with a nineteen-word one — routinely destroys a slide, and nothing in the object model says so. Only a picture does.”
So after an edit, Summa renders the slides it touched and gives the model the images to check. The renderer is a separate service: LibreOffice converts the deck to PDF in one invocation, and PyMuPDF rasterises the pages that were asked for. It is kept out of the API process because a conversion is several seconds of solid CPU and a few hundred megabytes of memory, and running it in-process would let one render starve every chat request alongside it. The service runs one conversion at a time, holds no database or object store, and needs nothing but its own bearer key.
Two decisions keep it safe. First, the renderer is not an editor. LibreOffice and PowerPoint do not render identically, and nothing it produces is written back into a document, so a rendering difference can never become data loss. Second, rendering is never allowed to fail an edit. By the time it runs, the change has landed; if rendering is unavailable, slow or broken, the edit stands and the model simply gets no pictures. Where no renderer is configured, the visual-check tool is not offered.
Rendering is kept proportionate: a two-word fix on slide 4 of a ninety-slide deck re-renders one slide, not ninety, because every returned image becomes a full picture in the next model request.
The limits, and what they cost
Every bound exists so that a single request cannot become unbounded work:
| Limit | Value |
|---|---|
| Presentation file size | 100 MB |
| Slides in a deck | 500 |
| Package entries / expanded size | 40,000 / 800 MB |
| Shapes inspected per slide | 400 |
| Text per element in a snapshot | 1,200 characters |
| Operations per edit | 40 |
| Deck size for visual review | 50 MB |
The snapshot cap is enough to identify and rewrite a real title or paragraph, and short enough that a deck full of dense notes cannot spend a whole context window on one inspection.
The other costs are plain. Run-by-run replacement misses text split across runs. Element references such as element_3_2 belong to one snapshot and are not durable. Replacing a picture means adding a new one in the old frame and removing the old shape, which is as close to in-place as the format allows. The visual check shows roughly what PowerPoint will show, not exactly.
What we would generalise
For anyone letting a model edit real documents, four things carried most of the weight:
- Define fidelity as what survives, and test for it. Edit one thing and check that unrelated things, including parts you do not understand, are still there.
- Verify before you replace. Reopen what you wrote, apply plans all-or-nothing, and use the provider’s preconditions so a concurrent save becomes a conflict, not a loss.
- Refuse with directions. A model fixes a clear refusal that says where the content should go; nobody notices a silent drop.
- Give the model eyes, but keep them out of the write path. A best-effort visual check can only improve an edit, never block one.
Summa is hosted in the EU and does not train on customer data. The decks it edits stay the customer’s decks, with the changes they asked for and nothing else.