Skip to content

define-xml

Build, validate and render Define-XML 2.1 for SDTM datasets from a study folder and mapping spec, and report coverage of datasets, variables and codelists. Use when asked to create, check or review define.xml or its HTML rendering.

Stage Clinical data
Tier 1 (deterministic tool)
Standards Define-XML 2.1, SDTMIG 3.4, CDISC CT, ODM 1.3.2
Minimum pharmaskills 0.3.0
Inputs study folder, mapping spec yaml, ct package, define xsd
Outputs define xml, define html, define validation json, define review md
Verified by define build, define validate, define render

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 define-xml (see Install).

Purpose

Produce and check the Define-XML 2.1 metadata file and its HTML rendering for a clinical programmer or data standards lead. The skill adds no new tool code: it drives the existing deterministic pharmaskills define commands, interprets their reports and writes a short, honest review summary. Everything is a draft for qualified human review.

When to use / when not to use

Use to build define.xml from a study folder and mapping spec, to validate an existing define.xml, to render it for review, or to explain validation findings.

Do not use for: ADaM Define-XML (the v1 builder describes the SDTM datasets of a study folder; say so and mark any ADaM description unverified), generating datasets (use sdtm-mapper), final submission packages without programmer and QA review, or hand-editing define.xml.

Inputs

Required: a study folder (study.yaml, raw/) and a mapping spec YAML, or an existing define.xml to validate. Optional: a CDISC controlled terminology package or subset file (pharmaskills ct sync or --ct-file), the official CDISC Define-XML 2.1 XSD (for --xsd).

Ask once for anything missing, then proceed with stated assumptions and [DATA NEEDED: ...] placeholders. State the region assumed (US FDA with ICH unless told otherwise) and the CT version used; "unversioned" when a subset file without a version was used.

If pharmaskills is not installed, tell the user to run uv tool install pharmaskills and check pharmaskills --version against min_pharmaskills. Without the tool, produce only a checklist of what to verify, marked unverified, and no define.xml.

Workflow

  1. Locate inputs. Confirm the study folder, the spec and the CT source exist. If the spec is missing, stop and point to sdtm-mapper; never write a spec from memory.
  2. Build. pharmaskills define build <study> --spec <spec> --ct-file <ct> --out out/ writes define.xml, define.html and define.validation.json. Use --json to keep the summary (datasets, engine errors, validation) as out/define_build.json.
  3. Validate. pharmaskills define validate out/define.xml (exit 0 passed, 2 findings). With the official schema add --xsd <path>; without it the XSD pass is skipped and the report says so. Never describe a skipped pass as passed.
  4. Render. pharmaskills define render out/define.xml --out out/define.html for review.
  5. Coverage. From the report and build summary confirm: every dataset of the study is described, engine errors are 0, variables match names and lengths, every CodeListRef resolves. List each finding with its rule id and a proposed spec change.
  6. Repair loop (maximum 3 iterations). Fix findings by changing the spec or the CT file and rebuilding. Never edit define.xml by hand and never weaken a check.
  7. Document. Write out/define_review.md from templates/define-review.md, then insert the draft banner and provenance with pharmaskills docs banner --apply out/define_review.md.
  8. Report using the output contract below.

Output contract

Under out/:

File Content
define.xml Define-XML 2.1 describing the datasets of the study
define.html Self-contained HTML rendering
define.validation.json Engine, version, errors, warnings, passes that ran
define_build.json Datasets, engine errors, validation outcome (from --json)
define_review.md Summary with draft banner, provenance, open items

State plainly in the answer: the validation engine and which passes ran, the number of datasets, error and warning counts, the CT version, and what needs human input.

Verification

Run and report pass or fail for each: define build (exit 0), define validate (exit 0), define render. Acceptance on the synthetic benchmark: schema-structural pass with zero errors, every dataset and variable present, every codelist reference resolves. A planted broken file must fail with exit 2. On failure fix the spec and rerun up to three times, then report what remains. The structural pass is not a substitute for the XSD pass or for CDISC CORE; say which ran.

Guardrails

  • Insert the draft banner in every generated document; never claim the file is XSD-valid, submission-ready or CORE-clean unless the report shows that pass ran and passed.
  • Never fabricate codelists, terms, variables, origins or methods; never hand-edit define.xml. Missing items become spec or CT changes plus a [DATA NEEDED: ...] placeholder.
  • Controlled terminology version is pinned in the review summary; do not mix versions.
  • Warn when inputs look like real patient data (pharmaskills docs detect-pii).
  • Every claim about a guideline cites identifier and section (see references/).

References

  • references/define-xml-notes.md - Define-XML 2.1 structure, what the structural pass checks
  • references/validation-rules.md - rule ids reported by define validate and how to fix them
  • Public sources: CDISC Define-XML v2.1 specification (cdisc.org/standards/data-exchange), FDA Study Data Technical Conformance Guide, CDISC SDTMIG 3.4.

Templates: templates/define-review.md. Script: scripts/run_define.sh (thin wrapper around pharmaskills define build and validate).

Examples

Worked example with inputs and outputs: examples/clinical-data/define-xml/. Synthetic inputs: skills/define-xml/evals/fixtures/ (study folder, spec, CT subset, a broken define).

Worked example

Committed example with inputs and outputs: examples/clinical-data/define-xml/.

Inputs: skills/define-xml/evals/fixtures/tiny-study (synthetic raw EDC exports), fixtures/spec.yaml (mapping spec) and fixtures/ct_subset.txt (CDISC CT subset).

pharmaskills define build fixtures/tiny-study --spec fixtures/spec.yaml \
  --ct-file fixtures/ct_subset.txt --out out
pharmaskills define validate out/define.xml
pharmaskills define render out/define.xml --out out/define.html
File in out/ Origin
define.xml, define.html, define.validation.json define build (tool output)
define_build.json define build --json summary (datasets, errors)
define_review.md drafted summary with draft banner and provenance
refusal_*.md what a correct agent says for the adversarial cases

The XSD pass needs the official CDISC schema (not bundled): pass it with --xsd. Synthetic data only. Not a validated system; for qualified review.

Skill source: skills/define-xml/SKILL.md