Schema Troubleshooting Clinic¶
Practice diagnosing schema errors with the command line and the Python API. Each exercise starts from a deliberately broken file: you read the error output, then fix the file.
Note
Install ddi-l in editable mode (pip install -e .) so the
module imports resolve.
1. Trigger a failing validation¶
- Run
mkdir -p clinicto create a workspace that keeps the broken instance separate from the source samples. - Copy
examples/Quality_of_Life.xmltoclinic/broken-instance.xml. - Remove a required attribute (for example the
versionon aStudyUnit) using your editor. - Run
ddi validate clinic/broken-instance.xmlto list each issue with its message, line and XPath. Add--format jsonfor a JSON array instead. - Note the XPath and message for the failing node.
2. Reproduce the error programmatically¶
-
Launch a Python session and validate the same file with the schema loader. Passing
raise_error=Falsecollects the full error list instead of raising on the first failure: -
Compare the output to the CLI JSON structure. Both surfaces expose the same error metadata so you can choose whichever fits your tooling.
3. Connect findings to lint rules¶
- Open
docs/validation.mdand identify which lint rules would catch similar mistakes (for example, missing agency identifiers). - Update your lint profile to include those rules by calling
configure_lint()in a Python session or editing your team profile file. -
Still in Python, execute
run_profileagainst the broken instance to confirm the rule set surfaces the issue before the schema fails:from ddi_l.io import read from ddi_l.lint import DDI_PROFILE_DEFAULT, configure_lint, run_profile configure_lint() # optionally tighten agencies, citation rules, etc. document = read("clinic/broken-instance.xml") result = run_profile(document, DDI_PROFILE_DEFAULT) for finding in result.lint_findings: print(finding.rule_id, finding.message)
4. Establish a remediation checklist¶
- Ensure the failing node's namespace prefix is registered so schema lookups can resolve the element correctly.
- Restore required attributes and run
ddi validateuntil the command reportsDocument is valid.. - Capture representative examples of the error and fix in your team's runbook so future incidents can be triaged faster.