rtfstruct: AST‑First RTF Parser for AI Ingestion Pipelines
Parse RTF into a neutral AST, preserve structure, expose diagnostics, and export to JSON, Markdown, or RTF.
Add rtfstruct to your ingestion pipeline and validate diagnostics on legacy documents.
Summary
RTF remains a common format in legal, medical, and legacy business documents, but standard pipelines flatten it to plain text, losing tables, headings, footnotes, and links. The author built rtfstruct, a Python 3.11+ library that parses RTF into a neutral AST preserving paragraphs, inline styles, lists, tables, links, fields, footnotes, images, metadata, source spans, and diagnostics. The library exposes JSON, Markdown, and RTF round‑trip exports, and returns diagnostics with severity, code, message, and source location. Existing Python tools either strip RTF to text, generate RTF only, or are Java‑only, leaving a gap for AI ingestion pipelines that need structured input. rtfstruct fills that gap by providing an open‑source, AST‑first parser with first‑class diagnostics and source spans.
The tool is part of Sourcetrace by Lumen & Lever and is designed for production ingestion pipelines that require traceability and structured data for AI models.
Key changes
- AST preserves paragraphs, styles, lists, tables, links, fields, footnotes, images, metadata, and source spans
- Diagnostics returned with severity, code, message, and source location
- JSON, Markdown, and RTF round‑trip exports
- Python 3.11+ compatible, open‑source under Apache‑2.0
- No external dependencies; pure Python
- Designed for AI ingestion pipelines requiring structured input
- Handles malformed Unicode escapes and other legacy issues
- Part of Sourcetrace by Lumen & Lever