DocXCast
"Your template is the mold. Data is poured in, documents take shape."
🪄 About
DocXCast turns a Word document's content controls into a typed schema, and casts your data back into a formatted document.
The Idea:
A .docx template is a natural schema editor. In Word's Developer tab, anyone can insert content controls and describe them:
| Word control property | Role in DocXCast |
|---|---|
| Title | field name (e.g. name) |
| Tag | extraction requirement for the LLM (e.g. the candidate's full name) |
| Repeating section | array of records |
| Building block gallery | Section with its own extraction rule |
Group control with a name? Title |
conditional block (see below) |
Locked control (sdtLocked) |
required field |
The full control inventory — every construct's Word-visible pseudo-structure and the OOXML it is made of — lives in SYNTAX.md.
Two independent capabilities:
derive_schema(template)— read the controls and produce aSchema, serializable to JSON Schema for LLM structured extraction.render(template, data)— pour data back into the template: clone repeating sections, fill values, unwrap controls, keeping every run's formatting.
⚡ Key Features
- Your template IS the schema — field names, extraction requirements and repeats all live in the docx, editable by non-programmers.
- Typed control mapping — text →
string, dropdown →enum, date / date-time →format, checkbox →boolean, picture → derived and removed. - LLM-friendly contract validation —
schema.validate(data)returns structured, machine-readable issues (path/code/message/expected/got) that can be fed back into an LLM correction loop. - Lenient by default, strict on demand — missing fields keep their template values;
strict=Trueraises on the first error. - Clean output — controls are unwrapped by default;
keep_controls=Truekeeps them for round-trip editing. - Zero magic — a single runtime dependency (
python-docx).
🚀 Quick Start
from docxcast import derive_schema, render
schema = derive_schema('resume-template.docx')
# hand this to your LLM as the extraction contract
json_schema = schema.to_json_schema()
# validate what the LLM extracted
report = schema.validate(data)
if not report.ok:
# feed report.issues back into the LLM for correction
...
# cast data into the template; controls are unwrapped
result = render('resume-template.docx', data)
result.save('resume-output.docx')
📏 Validation
Schema.validate() never raises; it returns a ValidationResult:
result.ok # False if any error-level issue exists
result.errors # missing_required / type_mismatch / enum_invalid / format_invalid
result.warnings # unknown_key
render(..., strict=True) raises RenderError on the first error-level issue.
🔀 Conditional Blocks
Wrap a block in a group control and mark the guarded control's Title with a trailing ? (TS-style): a falsy value removes the whole group — label text included — while a truthy value fills normally.
Nationality: [nationality?] truthy → "Nationality: Chinese" falsy → the line is gone
Work Experiences both the heading and the repeat
[repeat: work_experiences?] disappear when the array is empty
The ? is a render directive only — the derived schema (and the LLM contract) see a plain nationality field. Marker placement, inline vs block-level drops, positional has_prev? / has_next? separators and every misuse error live in SYNTAX.md.
⚠️ Limitations
picturecontrols are recognized in the schema but removed on render (no image insertion yet).- Date values are written verbatim; the template's display mask is not enforced.
- Unnamed controls are skipped in the schema — every field needs a Title to be addressable.
- No whitespace control: text outside a dropped inline conditional span survives — put separators inside the span.
Metadata
Release files for docxcast 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| docxcast-0.1.0.tar.gz | 46.5 kB | Without provenance | Details for docxcast-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| docxcast-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for docxcast-0.1.0-py3-none-any.whl |
Total release size: 63.0 kB
Release files / docxcast-0.1.0.tar.gz
| Download URL | docxcast-0.1.0.tar.gz |
|---|---|
| Size | 46.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
257388be5ed3d90bf2bb22e9e332035d85e602bdfea7be9fb8dcc2a0c3b29231
|
|
BLAKE2b-256 checksum How to use checksums |
fe9108eb3255b2731363eaf98aab0f735cfb96a937055f4d314e6972ea4b2d67
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / docxcast-0.1.0-py3-none-any.whl
| Download URL | docxcast-0.1.0-py3-none-any.whl |
|---|---|
| Size | 16.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
035b97ed8d5c6aab089f7747367f00f69983537b8de1d5a536297f9b957c6a9c
|
|
BLAKE2b-256 checksum How to use checksums |
e3e9bfbdafa1c7979fb738f1b881a7d2069e7466141ff7b0d058b730b2e564c1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for docxcast 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.