What you will finish with
The final handoff is not a lonely .md file. It is a small reviewable package:
clean-document.md— the Markdown a reader or publisher will use.source-inventory.json— file type, source hash, headings, table evidence, link evidence, and stop reasons.link-ledger.json— each visible label joined to its exact Word relationship or PDF URI annotation.conversion-report.json— repair log, clean checks, and negative mutation results.preview.html— a rendered GitHub Flavored Markdown review surface.README.md— reproduction commands, tool versions, boundaries, and handoff notes.
In the retained run, the Word and PDF routes ended with byte-identical Markdown. Both passed one title plus six section headings, two tables with seven body rows, five link labels and destinations, thirteen source-prose checks, and five deliberately damaging mutations.

Use the exact tested materials
Download the complete review kit, or inspect the synthetic Word source, PDF source, expected structure, and clean Markdown example separately.
Use three roles, not one giant prompt
- Docling creates the draft. It parses either DOCX or PDF and exports Markdown. The raw file is retained unchanged.
- AI orchestrates a minimal repair. It compares the draft with source-native evidence: Word styles, PDF font sizes, table boundaries, OOXML hyperlink relationships, and PDF URI rectangles. It changes Markdown syntax only where the evidence is explicit.
- An independent validator releases or rejects. It checks exact headings, cells, labels, destinations, required prose, forbidden page furniture, local-path leaks, and rendered table count. It also proves that five damaged copies fail.
Docling's official usage documentation supports the basic convert-and-export path. The project has also documented a history of PDF links and lists not being preserved in some conversions. That is why this workflow never treats a successful export command as proof that links survived. PyMuPDF supplies a second channel: page link records with URI and rectangle information.
Before you start
The downloadable script pins the retained tool versions in the review kit: Python 3.12, Docling 2.121.0, PyMuPDF 1.28.2, python-docx 1.2.0, and markdown-it-py 4.2.0. Use an isolated environment because Docling installs parsing and model dependencies that do not belong in your application runtime.
python3 -m venv md-env
md-env/bin/python -m pip install -r requirements.txt
Put the source in a fresh work folder. If it contains private or regulated information, do not upload it to an unapproved service. Use an approved local workflow or substitute synthetic values first. Keep one untouched source copy for the entire conversion.
Step 1 — Fix the source and expected result
You do: place the original .docx or born-digital .pdf in the folder. Write down what must survive before the converter runs. For the practice document, the contract is one title, six section headings, two tables, seven table body rows, five external links, and no repeated page header or footer.
Ask the AI:
Inspect this source only. Do not convert or rewrite it yet.
1. Compute its SHA-256.
2. If it is DOCX, render every page for visual review.
3. Report page count, file type, and whether a PDF is encrypted.
4. Save the independently authored acceptance counts beside the source.
5. Do not infer content that is not visible or structurally encoded.
AI does: hashes the source, renders the Word document, and records the starting boundary. The synthetic fixture is three pages. Its DOCX has real heading styles, two Word tables, and five OOXML hyperlink relationships. Its PDF export is born-digital, unencrypted, and contains five clickable URI annotations.
Check the result: open every rendered Word page at full size. Confirm that text is not clipped, headings do not collide with the repeated header, tables fit, links have descriptive visible labels, and the fixture contains no private data.
Output: untouched source file, source hash, rendered pages, and expected-structure.json.
Stop if: the expected result was written after looking at the converter's output. That would let the draft grade itself.

Step 2 — Run a fail-closed preflight
You do: confirm that you are authorized to process the document. If it is Word, resolve tracked changes and comments or decide explicitly that they must be preserved outside this workflow. If it is PDF, determine whether selectable text exists.
Ask the AI:
Create source-inventory.json before conversion.
For DOCX, inventory Title and Heading styles, tables, and hyperlink relationships.
For PDF, inventory page count, encryption, selectable-text count, font-size
heading candidates, repeated top/bottom text, and URI annotations with rectangles.
Return stop_reasons. Stop on an encrypted or image-only PDF, unresolved Word
changes, merged table cells, or a link rectangle that has no unambiguous label.
AI does: uses python-docx for Word structure or PyMuPDF for PDF evidence. In the retained PDF run, 30-point text identifies the document title, 20-point text identifies four level-one Word sections, and 14-point text identifies two level-two subsections. Repeated top and bottom lines are marked as page furniture rather than body content.
Check the result: confirm the evidence is source-native. A PDF heading should have a page number and font size. A link should have a label, exact URI, page, and rectangle. The stop list must be empty before the next step.
Output: source-inventory.json with born_digital: true, seven heading nodes, five mapped links, and no stop reason for this fixture.
Stop if: the PDF is mostly images, OCR confidence is needed, a table contains merged cells, or a link label cannot be mapped without guessing. Those are new workflows, not small repairs.

Step 3 — Create and keep the raw Docling draft
You do: run the same converter against the Word and PDF inputs. Do not overwrite the first export with a cleaned version. The raw draft is evidence of what the parser actually produced.
Ask the AI:
Run Docling DocumentConverter on the source and export Markdown.
Save it as raw-docling.md without manual cleanup.
Then diagnose structural syntax defects only:
- heading levels,
- list markers,
- table column boundaries,
- link labels and destinations,
- repeated page furniture.
Do not rewrite prose.
AI does: calls Docling's conversion path and saves the export. The Word draft is already strong. The PDF draft retains both tables and all five link strings, but it assigns the title and every section the same ## level, carries a PDF bullet glyph into list and link labels, and emits the destination containing parentheses without the safer angle-bracket form.
Check the result: count what is present, but do not call it clean merely because the count is correct. Seven labels can exist with the wrong hierarchy. Five link strings can exist while one Markdown destination parses incorrectly.
Output: raw-docling.md plus a defect list. The publication gate remains closed.
Stop if: a paragraph, table, or link is missing and no source-native evidence can reconstruct it. Missing content is not permission for a model to paraphrase.

Step 4 — Repair the heading hierarchy only
You do: read the intended hierarchy from Word styles or the PDF font-size ledger. Do not decide levels by how important a heading sounds.
Ask the AI:
Repair heading markers on exact heading lines only.
Mapping rule:
- Word Title or largest PDF heading size → #
- Word Heading 1 or next PDF heading size → ##
- Word Heading 2 or next PDF heading size → ###
Record each before and after line. Do not promote body prose, rename a heading,
or change the order.
AI does: builds an exact text-to-level map from the inventory. It changes Markdown markers, not wording. The final hierarchy has one # title, four ## sections, and two ### subsections.
Check the result: compare the complete heading list with the expected structure in order. Do not merely count seven lines; the levels and labels must both match.
Output: a heading repair ledger and a 7-of-7 heading pass.
Stop if: multiple body lines share the same font size as a heading and the hierarchy is ambiguous. Ask the document owner to identify the intended sections.

Step 5 — Normalize tables without moving a cell
You do: inspect each source table for merged cells, nested content, line breaks inside cells, and literal vertical bars. GitHub Flavored Markdown tables are appropriate only for a simple rectangular grid.
Ask the AI:
Normalize simple tables to GitHub Flavored Markdown.
Preserve row order, column order, and exact cell text.
Remove decorative bold from header cells.
Use a consistent --- separator row.
Escape a literal | inside a cell as \|.
Stop on merged cells instead of flattening them silently.
AI does: replaces Docling's HTML entity for the activity Draft | review exercise with an explicit escaped pipe, removes presentation-only bold from header cells, and normalizes separator rows. It does not change any cell value.
Check the result: parse the Markdown as a table. Compare every row and cell against the source contract. The retained result has two tables, seven body rows, and no extra column created by the literal pipe.
Output: two clean GFM table blocks with all cells intact.
Stop if: the table has merged cells. Ask the owner to choose an HTML table, redesign the data as multiple tables, or keep that section outside the Markdown target.

Step 6 — Reattach links from an independent ledger
You do: review visible link labels and source destinations separately. A copied label does not prove the URL survived.
Ask the AI:
Build link-ledger.json from the source, not from the Markdown draft.
For Word, read external hyperlink relationships.
For PDF, read URI annotations and extract the visible label inside each rectangle.
Map a link only when label and destination are unambiguous.
If a URL contains parentheses or spaces, wrap the destination in <...>.
Return unresolved instead of guessing.
AI does: creates five ledger rows and rebuilds the Markdown link syntax from those verified pairs. The last URL contains parentheses and a query string, so the clean output uses [Draft resource example](<https://example.com/resource_(draft)?mode=review>).
Check the result: compare all five labels and destinations. Then parse the clean Markdown links and confirm that they reconstruct the same pairs. The retained result has five mapped rows and zero unresolved rows.
Output: link-ledger.json and five verified GFM links.
Stop if: a rectangle covers multiple labels, a visible URL differs from the annotation, or a destination is absent. Surface the conflict to the owner.

Step 7 — Prove the validator can reject damage
You do: protect the clean candidate, then create five disposable copies. Damage one property at a time so each failure is attributable.
Ask the AI:
Run the independent validator on five isolated mutations:
1. demote one heading;
2. delete one table cell;
3. change one URL;
4. add an invented heading;
5. remove the escape before a literal table pipe.
Each mutation must return FAIL. Then rerun the untouched clean candidate.
AI does: compares exact heading objects, parsed table grids, parsed link pairs, thirteen required source-prose fragments, forbidden page-furniture strings, and rendered table count. It rejects all five mutations. The validator reads the expected contract and parses the final Markdown; it does not trust the converter's reported counts.
Check the result: look for five explicit rejection records. A missing rejection is a failed test, even if the clean candidate passes. After the negative run, the untouched baseline must still pass seven headings, two tables, five links, and thirteen prose checks.
Output: conversion-report.json with mutation_gate: PASS and five rejected mutations.
Stop if: any damaged copy passes. Fix the validator before changing the clean Markdown.

Step 8 — Render, review, and package the final result
You do: open preview.html as a reader, not as a code reviewer. Review at desktop and narrow mobile widths. Scroll wide tables horizontally rather than shrinking cell text until it becomes unreadable.
Ask the AI:
Render the clean Markdown with GitHub Flavored Markdown rules.
Check that headings are visible in order, both tables render, no page header or
footer remains, and no file:// or local user path appears.
Package the clean file, inventory, link ledger, report, preview, and README.
Report final hashes, limitations, and the result from both source routes.
AI does: renders the final document, writes the six-file handoff, and compares the Word and PDF outputs. Both routes end with SHA-256 3271f61bd7fc381fe0972efca1eee45ea83533038738f0ba32316cb210818c19.
Check the result: read the final page from top to bottom. Verify that the schedule row still reads Draft | review exercise inside one cell. Click-check only destinations you are authorized and comfortable visiting. Confirm the report names the untested boundaries.
Output: release-ready clean-document.md, five supporting files, and a complete review kit.
Stop if: the rendered page changes the meaning of the source, a table overflows without a scroll affordance, a link differs from the ledger, or the evidence package contains temporary or personal paths.

Run the tested converter yourself
Download the converter and gate, the eight-step prompt contract, and the review README. From the extracted kit, run either route:
md-env/bin/python document-to-markdown.py remote-workshop-handbook.docx \
--expected expected-structure.json --output out-docx
md-env/bin/python document-to-markdown.py remote-workshop-handbook.pdf \
--expected expected-structure.json --output out-pdf
Both commands should print status: PASS. Inspect the retained test results for tool versions, repair records, mutation failures, hashes, and evidence boundaries.
Adapt the workflow without weakening it
For a real document, replace the fixture and rewrite the expected structure before the first conversion. Do not copy the practice counts. If the new source has twelve headings, three tables, and eight links, the new contract should say so. Add checks for any feature you decide to support; do not quietly broaden the claim.
The useful pattern is stable even when tools change: keep the raw conversion, repair from independent source evidence, prove the validator can fail, and package the result with its limits. That turns “AI converted my file” into a result another person can inspect and trust.
