adam-spec¶
Specify ADSL and ADAE from SDTM datasets and the SAP, then build the datasets, derivation programs and spec workbook with unit-tested derivations. Use for ADaM specification, ADSL or ADAE derivation, TRTEMFL or population flags.
| Stage | Clinical data |
| Tier | 1 (deterministic tool) |
| Standards | ADaMIG 1.3, ADaM OCCDS 1.0, SDTMIG 3.4, ICH E9 |
Minimum pharmaskills |
0.3.0 |
| Inputs | sdtm xpt datasets, sap, study yaml |
| Outputs | adam spec yaml, adam spec xlsx, adsl xpt, adae xpt, adsl py, adae py, adam build report json, adam test report json |
| Verified by | adam build, adam test |
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 adam-spec (see Install).
Purpose¶
Produce a reviewable specification and the derived ADSL and ADAE analysis datasets for a
statistical programmer, starting from SDTM datasets and the statistical analysis plan (SAP).
You translate SAP definitions into a declarative spec (never into data), the deterministic
pharmaskills adam engine derives the datasets, and pharmaskills adam test proves the key
derivations. Everything is a draft for qualified human review.
When to use / when not to use¶
Use to specify or derive ADSL (population flags, treatment variables, treatment dates, age groups) and ADAE (treatment-emergent flag, analysis dates, severity, duration, first occurrence), or to check existing ADSL and ADAE derivations against the SAP.
Do not use for: any other ADaM dataset (ADTTE, ADLB, ADVS, ADEFF and all BDS parameter
datasets are out of scope in v1; say so and offer a specification outline marked unverified),
SDTM mapping (use sdtm-mapper), Define-XML (use define-xml), or real patient data that has
not been de-identified. Never hand-edit a derived dataset or a flag value.
Inputs¶
Required: SDTM XPT datasets DM, EX and AE (a folder of .xpt files or a study folder with
out/sdtm/xpt, gold/sdtm or sdtm), and the SAP (DOCX or Markdown) sections on analysis
populations, treatment definitions, treatment-emergent adverse events and subgroups.
Ask once for anything missing, then proceed with stated assumptions and [DATA NEEDED: ...]
placeholders. Typical gaps: follow-up window length, partial date rule, definition of the
safety population, age band cut points.
State the region assumed (US FDA with ICH unless told otherwise). If pharmaskills is not
installed, tell the user to run uv tool install pharmaskills, check pharmaskills --version
is at least min_pharmaskills, and produce only the spec outline and notes, clearly marked
unverified, with no datasets.
Workflow¶
You are the model in steps 1, 2 and 6. Everything else is a deterministic CLI call.
- Read the SAP. Extract the definitions listed in
references/derivations.md(population, TRT01P and TRT01A, TRTSDT and TRTEDT, treatment-emergent window, partial and missing date rules, severity coding, age groups). Quote the SAP section for each. Where the SAP is silent, choose the documented default, record it as an assumption and flag it. - Write
adam_spec.yamlfromtemplates/adam_spec.yaml: arms keyed by ARMCD, age bands,followup_days,partial_start(conservative,earliestorlatest),missing_start_is_emergent,safety_min_dose. Never put data values in the spec. - Build.
pharmaskills adam build <sdtm-or-study> --spec adam_spec.yaml --out out/writesadsl.xpt,adae.xpt, Dataset-JSON,adam_spec.xlsx,adsl.py,adae.pyandadam_build_report.json. The same inputs give byte-identical files. - Test.
pharmaskills adam test <sdtm-or-study> --spec adam_spec.yaml --expected expected_values.yaml --out out/adam_test_report.json. Built-in checks cover one row per subject, SAFFL from exposure, TRTEMFL against an independent recomputation and record counts. Buildexpected_values.yamlfrom the raw SDTM by hand for known cases (pre-treatment event, partial start date, missing start date, event inside the follow-up window); seetemplates/expected_values.yaml. Never copy values from the build output into it. - Repair loop (maximum 3 iterations). On a failure find the cause in the spec or the SAP reading, change the spec, rebuild and retest. Never change a dataset value or weaken a check.
- Document. Write
out/adam_spec_notes.mdfromtemplates/adam-spec-notes.md: decisions with SAP citations, tool counts, assumptions, open items. Insert the draft banner and a provenance block withpharmaskills docs banner --apply out/adam_spec_notes.md. - Report using the output contract below.
Output contract¶
Under out/:
| File | Content |
|---|---|
adam_spec.yaml |
Declarative spec filled from the SAP |
adam_spec.xlsx |
Variable list (dataset, label, type, source, derivation) and parameters |
adsl.xpt, adae.xpt, adsl.json, adae.json |
XPT v5 and Dataset-JSON v1.1 datasets |
adsl.py, adae.py |
Readable derivation programs that call the tested library |
adam_build_report.json |
Counts, flags, input and output hashes |
adam_test_report.json |
One entry per derivation check with pass or fail |
adam_spec_notes.md |
Decisions, assumptions, open items, banner and provenance |
Dates are numeric SAS dates in XPT and ISO 8601 strings in Dataset-JSON. State plainly in the answer: the scope (ADSL and ADAE only), record counts, flag counts, check results and every assumption.
Verification¶
Run and report pass or fail for each: adam build (exit 0), adam test (exit 0, all checks),
pharmaskills docs banner applied to the notes. Acceptance on the synthetic benchmark PSK-001:
ADSL has one row per subject (138), SAFFL is Y for the 120 treated subjects, TRTEMFL matches
the independent recomputation for all 168 AE records, rebuild is byte-identical. On failure
fix the spec and rerun up to three times, then report what remains. No CDISC CORE ADaM run is
performed by this skill; say so and do not describe the datasets as conformant.
Guardrails¶
- Insert the draft banner in every generated document; never claim the datasets are validated, submission-ready or CORE-clean.
- Never fabricate data, subject values, dates, flags or SAP content. Missing SAP rules become
[DATA NEEDED: ...]placeholders plus a flagged assumption. - Never write or edit ADaM records directly and never run model-generated code over the data. Only the spec changes; the engine executes it.
- Refuse requests to set flags to improve a safety picture, to hide events or to bypass the SAP definition; offer a documented sensitivity analysis instead.
- ADSL and ADAE only; state that other ADaM datasets are out of scope in v1.
- Warn when inputs look like real patient data;
pharmaskills docs detect-piichecks this. - Every claim about a guideline cites identifier and section (see
references/).
References¶
references/derivations.md- supported derivations, rules, defaults and limits of v1references/adam-notes.md- ADaMIG 1.3 and OCCDS 1.0 notes with section citationsreferences/spec-format.md- the YAML spec and expected-values file formats- Public sources: CDISC ADaM Implementation Guide v1.3 and ADaM OCCDS v1.0 (cdisc.org/standards), ICH E9 (database.ich.org), CDISC SDTMIG 3.4.
Templates: templates/adam_spec.yaml, templates/expected_values.yaml,
templates/adam-spec-notes.md. Script: scripts/run_adam.sh (thin wrapper around
pharmaskills adam build and adam test).
Examples¶
Worked example with inputs and outputs: examples/clinical-data/adam-spec/. Synthetic inputs:
skills/adam-spec/evals/fixtures/ (DM, EX and AE of PSK-001, a SAP excerpt, expected values).
Worked example¶
Committed example with inputs and outputs: examples/clinical-data/adam-spec/.
Inputs (synthetic study PSK-001, subset of the gold SDTM): skills/adam-spec/evals/fixtures/sdtm
(DM, EX, AE) and skills/adam-spec/evals/fixtures/sap_excerpt.md.
Reproduce the deterministic outputs:
pharmaskills adam build skills/adam-spec/evals/fixtures/sdtm --spec out/adam_spec.yaml --out out
pharmaskills adam test skills/adam-spec/evals/fixtures/sdtm --spec out/adam_spec.yaml \
--expected skills/adam-spec/evals/fixtures/expected_values.yaml --out out/adam_test_report.json
File in out/ |
Origin |
|---|---|
adsl.xpt, adsl.json, adae.xpt, adae.json |
adam build (tool output, byte-identical on rerun) |
adam_spec.xlsx, adsl.py, adae.py, adam_build_report.json |
adam build |
adam_test_report.json |
adam test |
adam_spec.yaml |
the spec the agent filled from templates/adam_spec.yaml |
adam_spec_notes.md |
drafted narrative with draft banner and provenance |
refusal_*.md |
what a correct agent says for the adversarial cases |
Synthetic data only. Not a validated system; for qualified review.
Skill source: skills/adam-spec/SKILL.md