A 120-slide deck arrived on a Friday afternoon: revenue bridges, three-year projections, architecture diagrams, a table on slide 63 with more columns than the projector could show. The speaker notes were empty. Someone needed a narrated video by Monday.

The obvious approach is to render every slide and ask a vision model to describe it. It demos well, until slide 47 says “FY26 gross margin: 62.4%” and the model writes “around 60%,” or worse, invents “63.1%.” On a board deck, that is not a rounding error. It is a credibility incident. And if the deck is confidential, uploading it is a second incident.

The fix is an architectural boundary, not a better prompt. The format, layout graph, numbers, and export path stay deterministic. A small local model gets one narrow, reversible job: turn a structured summary into a sentence when a human left a gap.

This is the fourth article in the “10% AI, 90% deterministic code” series. The first three covered control-plane design, constrained output, and runtime choice. This one moves to a real document: the .pptx.

The file is a zip, not a picture

Rename a .pptx to .zip and open it. You will not find a document, but a package of XML parts, relationships, and media:

[Content_Types].xml _rels/.rels ppt/presentation.xml ppt/_rels/presentation.xml.rels ppt/slides/slide1.xml ppt/slides/_rels/slide1.xml.rels ppt/slideLayouts/slideLayout1.xml ppt/slideMasters/slideMaster1.xml ppt/theme/theme1.xml ppt/notesSlides/notesSlide1.xml ppt/media/image1.png 

This is OOXML (ECMA-376 / ISO 29500). The important word is package. slide1.xml is not necessarily the first slide. Order lives in ppt/presentation.xml, as slide IDs that point through relationships to parts. Parts copied from another deck may not follow slide order.

That breaks many parsers: they iterate slide1.xml, slide2.xml, … and produce a plausible deck until someone checks slide 12.

The package is a graph. A .rels file maps IDs to targets: slide to layout, layout to master, master to theme, slide to notes and media. Resolve the graph; do not guess from filenames.

import posixpath from zipfile import ZipFile from lxml import etree R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships" def read(z, part): return etree.fromstring(z.read(part)) def rels(z, part): base = posixpath.dirname(part) rp = f"{base}/_rels/{posixpath.basename(part)}.rels" return {r.get("Id"): (r.get("Type"), posixpath.normpath(posixpath.join(base, r.get("Target")))) for r in read(z, rp)} def slide_parts(z): pres = read(z, "ppt/presentation.xml") pr = rels(z, "ppt/presentation.xml") return [pr[s.get(f"{{{R}}}id")][1] for s in pres.findall(".//p:sldIdLst/p:sldId")] def chain(z, part): s, sr = read(z, part), rels(z, part) lp = next(t for typ, t in sr.values() if typ.endswith("/slideLayout")) l, lr = read(z, lp), rels(z, lp) mp = next(t for typ, t in lr.values() if typ.endswith("/slideMaster")) return [(s, sr), (l, lr), (read(z, mp), rels(z, mp))] 

That is the unglamorous part, and it is also the part that has to be right. Everything downstream trusts this graph.

The inheritance chain is the document

Most text is not fully specified on the slide. A title can inherit position from the layout, font from the master, and color from the theme. Bullet indentation and line spacing can come from higher up.

Placeholders are matched by idx and type, not by reading order. If you parse only slideN.xml, you will miss inherited geometry, apply the wrong font, or place a title at (0, 0). The slide will still “parse.” It will simply be wrong.

Resolve each shape against the chain before handing it to the renderer or model:

  1. Read the shape’s explicit properties.
  2. Find the matching placeholder in the layout.
  3. If a property is still missing, look in the master.
  4. Resolve theme colors, fonts, and effects last.

Coordinates are EMU. One inch is 914,400; a 16:9 slide is 12,192,000 × 6,858,000. Keep integers until the final conversion; early rounding drifts across grouped shapes.

Text extraction is deceptively simple:

A = "http://schemas.openxmlformats.org/drawingml/2006/main" def text_of(element): paragraphs = [] for p in element.iter(f"{{{A}}}p"): runs = [t.text or "" for t in p.iter(f"{{{A}}}t")] paragraphs.append("".join(runs)) return "\n".join(paragraphs) 

The hard part is not the string, but knowing which shape it belongs to, where that shape sits, whether it is a title, bullet, table cell, or chart label, and which part it came from.

Build a slide IR, not a prompt

The temptation is to serialize the XML into a model. Do not. XML is a transport format, not a context strategy: verbose, full of styling noise, and full of the numbers you do not want paraphrased.

Build a small intermediate representation instead. One slide, one object:

{"index": 47, "part": "ppt/slides/slide47.xml", "title": "FY26 margin bridge", "blocks": [ {"kind": "bullets", "text": ["Volume +3.1 pts", "Mix +1.8 pts", "Pricing +0.9 pts", "FX -1.4 pts"]}, {"kind": "table", "rows": [["Gross margin", "62.4%", "58.9%"]]}], "notes": null} 

Notice what is missing: pixels, prose, guesses. Every field is read from the package or resolved through inheritance. Every block points back to its part and shape ID, so a validator can prove where a sentence came from.

This IR is the contract. Renderer, notes generator, and tests all consume it. The model never sees the original file, and never gets to invent a table cell.

The local model gets one narrow job

The extractor fills almost everything: titles, bullets, tables, chart series, positions, existing notes. The gap is semantic — a slide has no notes, an image has no caption, a diagram needs one sentence of orientation.

That is the 10%.

For a missing note, the prompt is small: title, bullets, table deltas, chart labels, one line about any image. No full deck, no raw XML, no “world-class expert” preamble.

The output is constrained at the decoder, not requested in the prompt. A JSON Schema or GBNF grammar allows one object with one string field:

root ::= "{\"narration\":\"" sentence "\"}" sentence ::= char{40,320} char ::= [^"\\\x00-\x1F] | "\\\"" | "\\\\" 

With llama.cpp, the schema becomes a grammar, so the sampler cannot emit an unclosed quote or an extra key. The downstream parser needs no error handling for malformed JSON, because malformed JSON cannot be produced.

But grammar-constrained decoding solves syntax, not truth. The validator still has to check semantics:

import json, re def numeric_tokens(text): return set(re.findall(r"\d+(?:\.\d+)?%?", text)) def accept(narration, ir): facts = numeric_tokens(json.dumps(ir)) claimed = numeric_tokens(narration) return claimed <= facts 

If the note contains a number not in the IR, reject it. Retry once at lower temperature. If it fails again, fall back to a template: “This slide covers {title}. It contains {n} bullet points and a table with {rows} rows.” It is not elegant, but it is true and never blocks the export.

The model is allowed to choose words. It is not allowed to choose facts.

Where vision actually helps

A rendered slide is useful. A vision model reading it answers a narrower set of questions than most demos suggest.

Use vision for semantics that are genuinely visual:

  • “This diagram shows a three-stage funnel from acquisition to renewal.”
  • “The photo shows a warehouse floor with three picking zones.”

Do not use vision for numbers, table cells, or body text. Those are in the IR; take values from the XML.

A cheaper layer comes first: layout checks. Bounding boxes from resolved geometry flag shapes past the slide edge, overlapping the footer, or below minimum font size. Arithmetic, not inference, and no weights.

Vision earns its keep on the residual: an uncaptioned diagram, an unlabelled photo, a chart titled “Q4” whose meaning is not obvious. One sentence per asset, constrained to visible content.

Rendering is the hard deterministic part

The renderer is where “no Office dependency” becomes a pile of edge cases.

You need to handle:

  • DrawingML transforms. Position, size, rotation, flip, group composition, crop. A group’s children are relative to the group’s transform, not the slide.
  • Theme resolution. A color is a theme slot plus tint or shade; a font is a theme slot plus a script fallback.
  • Text layout. Font metrics, line spacing, bullet indents, autofit, vertical anchoring.
  • Font fallback. Embedded fonts may be absent, licensed, or subsetted. Different metrics reflow the text. Do not silently reflow a client’s slide: measure, clip, warn.
  • Images and effects. Transparency, gradients, shadows, soft edges are optional in the spec and uneven in the wild.

You do not need all of DrawingML, only the subset your decks use plus a visible fallback. A gray “unsupported effect” placeholder is honest; a silently wrong render is not.

Cache the render by a hash of slide XML, theme, and font set. A 100-slide preview should feel instant on second open. The cache key is a test fixture: if the hash changes, the output should change for a reason you can name.

The pipeline

Here is the whole system, with the boundary drawn where it belongs:

.pptx ──▶ package + relationships ──▶ slide IR (facts + provenance) │ ┌───────────────────────┴───────────────────────┐ ▼ ▼ deterministic renderer gap detector │ │ ▼ ▼ PNG + layout checks local LLM │ │ ▼ ▼ vision model (semantics) validator (facts) └───────────────────────┬───────────────────────┘ ▼ timeline / FFmpeg export 

Every arrow into the model is optional. Every arrow out of the model passes through a validator. If the model is unavailable, the pipeline still produces a deck with extracted notes and a template for the gaps. That is the difference between a feature and a dependency.

Failure isolation and tests

A parser meets files no one designed for: a deck zipped on a phone, a slide with 4,000 shapes, a corrupt relationship, a missing font, a merged-cell table that breaks your renderer. Treat each slide as a separate job: Ok(slide) or Err(reason). One bad slide gets one visible badge, not a crashed app.

Guard the package: reject path traversal, cap size and entry count, disable DTDs and external entities, keep targets inside the package.

Then build a golden corpus. Thirty real decks beat three hundred spec-written tests: tables, groups, rotated text, RTL, CJK, embedded images, and one deck assembled at 2 a.m. Hash the IR and the PNG; any change is a diff. For the model, measure factuality, not BLEU: every number must appear in the IR, and the note must name the title. Run offline.

The 10/90 split, in one sentence

Deterministic code owns the package, graph, geometry, facts, render, validation, and export. The model owns one paragraph when a human left a gap, and one caption when an image has no words.

That is not a compromise; it is the only division that survives a real deck, a real machine, no network, and a deadline.

A missing note is a gap, not an emergency: the renderer can still render, the exporter can still export, and the model can fail without taking the product down.

The best AI feature in a document tool is the one you can turn off and still have a document tool.

I’m building a local desktop tool that turns existing PowerPoint decks into narrated videos; the architecture above is the part that makes it boring enough to trust.

Previously: Part 1, Part 2, Part 3.

Originally published on Medium.