sdtm-mapper¶
Turn raw EDC exports into SDTM datasets (DM, AE, CM, VS, LB, EX, TS), a mapping spec, Define-XML 2.1, a reviewer's guide draft and a traceability matrix, validated and repaired in a loop. Use for SDTM mapping or conformance work.
| Stage | Clinical data |
| Tier | 1 (deterministic tool) |
| Standards | SDTMIG 3.4, SDTM v2.0, CDISC CT, Define-XML 2.1, Dataset-JSON 1.1, CDISC CORE |
Minimum pharmaskills |
0.2.0 |
| Inputs | raw edc exports, study yaml, protocol, ecrf annotations, licensed dictionaries |
| Outputs | sdtm xpt, sdtm dataset json, spec yaml, review queue xlsx, define xml, csdrg md, traceability csv, validation report json, run manifest json |
| Verified by | sdtm init, sdtm profile, sdtm validate-spec, sdtm review, sdtm build, sdtm validate, sdtm repair, sdtm document, sdtm run |
Draft for qualified review. Not a validated system and not 21 CFR Part 11 compliant.
Install only this skill: pharmaskills skills install --agent claude-code --skill sdtm-mapper (see Install).
Purpose¶
Produce a reviewable SDTM package from raw EDC exports for a clinical programmer or statistical
programmer. You propose a mapping specification (never data), the deterministic pharmaskills
engine executes it, the datasets are validated, failures are repaired by changing the spec, and
the package is documented (Define-XML 2.1, cSDRG draft, traceability matrix, run manifest).
Everything is a draft for qualified human review.
When to use / when not to use¶
Use when asked to map raw clinical data to SDTM, check or repair SDTM conformance, build a mapping specification, or create Define-XML or a reviewer's guide draft for SDTM datasets.
Do not use for: ADaM (use adam-spec), SEND (use send-checker), final submission packages
without programmer and QA review, real patient data that has not been de-identified, or MedDRA
and WHODrug coding without the user's licensed dictionary files. Do not hand-edit SDTM datasets.
Inputs¶
Required: a folder of raw EDC exports (CSV, XLSX, SAS7BDAT or XPT, one file per form) and a
study.yaml (STUDYID, arms, epochs, visits, trial summary). Ask once for anything missing, then
proceed with stated assumptions and [DATA NEEDED: ...] placeholders.
Optional: protocol DOCX (needed for TS and the visit schedule), eCRF annotations or a data
dictionary, licensed MedDRA or WHODrug files (path in pharmaskills.toml), a CDISC CT package
(pharmaskills ct sync).
Study folder layout:
<study>/study.yaml <study>/raw/*.csv <study>/dictionaries/*.csv <study>/protocol.docx
If pharmaskills is not installed, tell the user to run uv tool install pharmaskills, then
continue with template-only guidance clearly marked unverified. Check pharmaskills --version
is at least the version in min_pharmaskills.
Workflow¶
You are the model in steps 2 to 4 and 8. Every other step is a deterministic CLI call. Never write SDTM records yourself and never run code that you generated over the data.
- Draft the study metadata.
pharmaskills sdtm init <study> --protocol protocol.docx. Show the user the items to confirm and wait for corrections tostudy.yaml. - Profile.
pharmaskills sdtm profile <study>; readout/profile.json. Note date formats (including partial dates such asUN-MAR-2026), wide versus long layouts, key columns, site-specific codelist variants and mixed units. - Classify forms and propose the spec. Start from
pharmaskills sdtm propose <study> --no-model(deterministic skeleton), then complete it yourself. Readreferences/dsl.md. One row per target variable withconfidence(0 to 1) andrationale. Use only the 14 DSL operations. Route non-standard variables to the domainsupplist. Look up codelists withpharmaskills ct codelist <C-code>andpharmaskills ct lookup <value>. - Validate the spec.
pharmaskills sdtm validate-spec <study> --spec <spec>. Fix every error (exit 2) and rerun. Required variables must be covered; Expected variables are covered or justified underomit. - Review gate.
pharmaskills sdtm review <study> --spec <spec>writesreview_queue.xlsx(confidence below 0.8, or a Required variable mapped by derivation). In interactive use show the rows and ask the user to approve or reject; apply with--apply. In batch mode usepharmaskills sdtm run --auto-approve-above 0.8and report the unapproved rows. - Build.
pharmaskills sdtm build <study> --spec <spec>(XPT v5 and Dataset-JSON v1.1). The engine is deterministic: the same inputs give byte-identical files. - Validate.
pharmaskills sdtm validate <study>. It uses CDISC CORE whenPHARMASKILLS_CORE_PATHis configured, otherwise the native checks, and the report states which engine ran. Never describe native results as CDISC CORE results. - Repair loop (maximum 5 iterations). For each error propose a spec change with a
rationale, never a data edit:
pharmaskills sdtm repair <study> --max-iter 5. Stop when the error count does not fall between two iterations; list remaining issues with options. - Document.
pharmaskills sdtm document <study>writes Define-XML 2.1, the cSDRG draft, the traceability matrix and the run manifest. For everything in one call usepharmaskills sdtm run <study>. - Report using the output contract below.
Output contract¶
Under <study>/out/:
| File | Content |
|---|---|
sdtm/xpt/*.xpt, sdtm/json/*.json |
Datasets: DM (+SUPPDM), AE (+SUPPAE), CM, VS, LB, EX, TS |
../spec.yaml and review_queue.xlsx |
Mapping specification and the review queue |
define/define.xml, define/define.html |
Define-XML 2.1 and its rendering |
csdrg.md, csdrg.docx |
Clinical study data reviewer's guide draft |
traceability.csv |
Raw file and row for every SDTM record |
validation_report.json |
Engine, version, errors, warnings, notes |
run_manifest.json |
Versions, input and output hashes, verification results |
Every generated document carries the draft banner (the exact text from pharmaskills docs
banner) and a provenance block. State plainly in your answer: the engine used, error and warning
counts, the unapproved mappings, uncoded terms, and what needs human input.
Verification¶
Run, and report pass or fail for each: validate-spec, build (no build errors), validate
(zero errors, or each remaining issue listed with a suggested option), define validate
out/define/define.xml, traceability complete (run_manifest.json verification list). On failure
fix the spec and rerun up to three times, then report what remains. Do not weaken a check.
Acceptance on the synthetic benchmark (PSK-001 and PSK-002): zero errors, variable-level spec accuracy of 95 percent or higher, record match of 98 percent or higher, byte-identical rebuild.
Guardrails¶
- Insert the draft banner in every generated document; never claim the output is validated,
submission-ready or CORE-clean unless the report shows
cdisc-core. - Never fabricate data, terms, MedDRA or WHODrug codes. Without a licensed dictionary leave AEDECOD and CMDECOD empty and flag them in the cSDRG ("uncoded").
- Never write or edit SDTM records directly, and never run model-generated code. Only specs change; the engine executes them.
- Warn when inputs look like real patient data (names, dates of birth, addresses) and recommend
de-identification;
pharmaskills docs detect-piiimplements the check. - Region assumed: US FDA with ICH; state any other assumption. Controlled terminology version is pinned in the manifest.
- Dates that cannot be interpreted are left blank and reported, never guessed.
References¶
references/dsl.md- the mapping DSL: operations, reference rules, examplesreferences/review-workflow.md- confidence, review queue, approval statusesreferences/conformance.md- reading native and CORE reports, rule catalogue- Public sources: CDISC SDTM and SDTMIG 3.4, CDISC Controlled Terminology (NCI EVS), Define-XML 2.1, Dataset-JSON v1.1, PHUSE cSDRG template, CDISC CORE.
Templates: templates/study.yaml (study metadata skeleton) and
templates/review-checklist.md (what a reviewer checks in the queue). Scripts:
scripts/run_sdtm.sh (thin wrapper around pharmaskills sdtm run).
Examples¶
Worked example with inputs and outputs: examples/clinical-data/sdtm-mapper/. Synthetic study
folder for trying the workflow: skills/sdtm-mapper/evals/fixtures/tiny-study.
Worked example¶
Committed example with inputs and outputs: examples/clinical-data/sdtm-mapper/.
Inputs: skills/sdtm-mapper/evals/fixtures/tiny-study (a 15-subject synthetic study, STUDYID
PSK-T01) and the CT subset skills/sdtm-mapper/evals/fixtures/ct_subset.txt.
Command: pharmaskills sdtm run <study> --spec spec.yaml --ct-file ct_subset.txt --no-model
out/ holds the real outputs of that run: datasets (XPT v5 and Dataset-JSON), Define-XML 2.1
and its HTML, the cSDRG draft, the traceability matrix, the review queue, the validation report
(engine pharmaskills-native, not CDISC CORE) and the run manifest.
refusal_*.md show what a correct agent says to the two adversarial requests.
Everything is synthetic.
Skill source: skills/sdtm-mapper/SKILL.md