doc-extract

$npx mdskill add anthropics/healthcare/doc-extract

Extracts plain text from various document formats for processing

  • Reads input files of supported types (PDF, DOCX, XLSX, PPTX, RTF) and converts them to plain text.
  • Depends on liteparse for PDF/DOCX/XLSX/PPTX documents and rtf-to-text for RTF documents.
  • Decides the extraction method based on file type and uses appropriate tools (liteparse, pdftotext, rtf-to-text) to produce the text output.
  • Delivers the extracted text in JSON format via stdout for further processing or use by other components.

SKILL.md

.github/skills/doc-extractView on GitHub ↗
---
name: doc-extract
description: Extract plain text from a document file - PDF, DOCX, XLSX, PPTX, RTF, or plain text/markdown/HTML. Use when a binary document needs to be turned into text, for example a contract PDF or an EHR DocumentReference attachment. Other skills (fhir) invoke scripts/extract.ts directly; the contracts MCP server bundles its own copy (servers/documents/src/extract.mjs) so its bundle stays self-contained — port fixes to both.
---

# doc-extract

Shared document-to-text extraction. One script, no state: reads an input file, prints JSON to stdout, writes nothing to disk (PHI-safe — no caches, no temp files; callers own any caching).

## Setup (once)

```bash
cd <this skill dir> && bun install
```

This pulls [liteparse](https://www.npmjs.com/package/@llamaindex/liteparse) (the `lit` bin, used for PDF/DOCX/XLSX/PPTX, OCR included) and [rtf-to-text](https://www.npmjs.com/package/rtf-to-text) (RTF). Without it, PDFs still work via a `pdftotext -layout` fallback if poppler is installed; other binary formats require liteparse.

## Use

```bash
bun <this skill dir>/scripts/extract.ts <input-file> [--content-type <mime>]
```

Output on stdout:

```json
{ "text": "...", "method": "liteparse | pdftotext | rtf-to-text | passthrough", "pages": 12 }
```

- `text` is page-anchored for paged formats: `=== [page N] ===` markers between pages.
- `pages` is present when page markers exist.
- `method` is the extractor that actually produced the text.
- Format is taken from the file extension; pass `--content-type` (e.g. `application/pdf`) when the file has no useful extension, as with downloaded EHR attachments. Note liteparse refuses extension-less files, so those PDFs go through the `pdftotext` fallback.
- Errors print `{"error": "..."}` to stderr and exit 1.

## Table caveat

Tables with multiple value columns (option A vs option B, in-tier vs out-of-tier) can interleave columns line-by-line in the extracted text: fragments of adjacent cells alternate, and a cell's text can even land mid-sentence inside a neighboring column. Values usually survive, but which column a value belongs to can become ambiguous. When an answer comes from one column of a multi-column table and the document has no redundant restatement of the value elsewhere, verify it by reading the original page directly before treating it as ground truth. The extracted text's `=== [page N] ===` anchor tells you which page: pass it to the Read tool's `pages` parameter (e.g. pages: "37") to render just that page to vision instead of the whole document.

## For other skills

Import the functions instead of shelling out when you're already in bun TS:

```ts
import { extract, resolveLit } from "../doc-extract/scripts/extract";
const lit = resolveLit([myRoot]); // also checks myRoot/node_modules/.bin/lit
const text = extract(lit, "/path/to/file.pdf"); // string | null
```

The contracts skill consumes it this way (its ingest caching stays on the contracts side).

More from anthropics/healthcare

SkillDescription
clinical-note-extract-skillExtract structured data from clinical notes with span-level provenance and null-safety. Use when users say "extract [variables] from this note", "abstract this chart", "pull structured data from these notes", "what does this note say about [field]", or when building a chart-abstraction, registry, or cohort dataset from unstructured clinical text.
contractsAnswer a question across a corpus of contract documents with verified citations. Use when the user asks what a contract says, which contracts have a clause, what changed between amendments, or any question that needs reading and citing across a set of contract files. The corpus must be on the local filesystem (see README).
fhirConnect to a hospital's FHIR R4 server (Epic, Oracle Health/Cerner, MEDITECH, athenahealth, or any SMART-on-FHIR endpoint), pull a patient's clinical data and notes, and extract structured findings. Use when users say "connect to the EHR", "connect to Epic/Cerner", "pull notes for patient X", "what do the last 6 months of notes say about Y", or any task that starts from a live EHR rather than pasted text.
fhir-developer-skill>
fraud-detectionScreen a Medicare/Medicaid claims corpus for fraud, waste, and abuse and produce ranked, fully-cited investigation referrals for an SIU / program-integrity team. Use when asked to run a fraud sweep, screen claims for FWA, find billing anomalies, or generate investigation referrals over a claims dataset.
icd10-cm-skillExtract billable ICD-10-CM diagnosis codes from a clinical note the way a professional coder builds the claim. Use when users say "code this encounter", "assign ICD-10 codes", "what diagnosis codes apply", "code this chart", or when turning clinical documentation into claim-ready diagnosis codes.
prior-auth-review-skillAutomate payer review of prior authorization (PA) requests. This skill should be used when users say "Review this PA request", "Process prior authorization for [procedure]", "Assess medical necessity", "Generate PA decision", or when processing clinical documentation for coverage policy validation and authorization decisions.
procedure-codingAssign CPT and HCPCS Level II procedure codes from clinical documentation the way a professional coder builds the claim. Use when users say "code this encounter for procedures", "what CPT codes apply", "assign HCPCS codes", "code this op note", or when turning visit notes or operative reports into claim-ready procedure codes.