Define.xml is not documentation. It is the dataset's contract

By Pawan Rama Mali, Clinical AI Systems Architect

On most studies define.xml is produced near the end, generated from the datasets that exist, reviewed for completeness, and shipped. It is accurate, because it was derived from the thing it describes. It is also nearly useless as a control, for exactly the same reason.

A document generated from the build cannot disagree with the build. Every error it might have caught has already been baked in and then faithfully documented.

The order that makes it useful

Written first, define.xml is a specification. It states what variables will exist, with what labels, types, lengths, codelists and origins, before anyone writes the code that produces them. The build is then checked against it, and a mismatch is a finding rather than an update to the documentation.

Define.xml as an output versus as a contractGenerated at the end, define.xml only describes whatever was built and cannot disagree with it; written first, it is a specification the build is checked against, so a mismatch is a finding. Output or input, the order decides As an output (generated at the end) Build datasets Generate define.xml Describes whatever was built. It cannot disagree with it. As a contract (written first) Write define.xml the specification Build to it Check build against it. A mismatch is a finding. One artefact, written before the code, catches errors instead of documenting them.
Made last, define.xml can only agree with the build; made first, it can hold the build to account.

This is not a new idea, and most standards groups will say they already do it. In practice the specification usually lives in a spreadsheet, and define.xml is generated separately at the end from the datasets. The two are reconciled by hand, or not at all. Where they drift, the spreadsheet is treated as the intent and define.xml as the record, and nobody is quite sure which one the reviewer is reading against.

Origin is the field that carries the weight

Of everything define.xml captures, origin is the one reviewers use most and sponsors complete most casually. Collected, derived, assigned or predecessor: the distinction matters because it tells a reviewer where to look when a value is questioned.

What each origin value tells a reviewerThe four origin values, collected, derived, assigned and predecessor, each point a reviewer to a different place to confirm a questioned value. Origin tells the reviewer where to look ORIGIN WHERE THE REVIEWER LOOKS Collected The CRF field in the raw data Derived The method text and its source variables Assigned The rule or codelist that set the value Predecessor The variable in the source dataset
A derived origin only earns its place when the method lets a reviewer rebuild the value.

A derived variable whose origin says derived, with no method attached, has answered nothing. The method text is where the traceability actually lives, and it is frequently either absent, or a restatement of the variable name in longer words. "AVAL is the analysis value" is a complete sentence and an empty one.

A good method description lets a reviewer reconstruct the value from the source data without reading the code. That is the standard worth holding it to.

Codelists drift quietly

The second common failure is codelists that no longer match the data. Extensible codelists get extended during the study, a new term appears in the raw data, the derivation passes it through, and the define file still lists the original set. Nothing errors. The datasets are internally consistent. The define file is simply now describing a slightly different study.

This is worth an automated check rather than a review pass, because it is exactly the kind of thing human review is bad at: a comparison of two long lists that are almost identical. Comparing the distinct values present in each variable against the codelist declared for it takes minutes to automate and catches the drift on every run.

What changes when it is treated as a contract

Three things, in our experience. Dataset specifications stop diverging from the file that is actually submitted, because there is only one artefact. Review effort moves earlier, to a point where changes are cheap. And the conformance checks that everyone runs at the end start passing on the first attempt, because the build was written against the same definition the checks read.

None of this requires new tooling. It requires the file to be an input rather than an output.

Back to Insights