Validates TEI P5 XML files for archival and historical editions: checks well-formedness, TEI structure, official RelaxNG schema, and adds semantic checks for broken IDs, duplicate xml:id, impossible dates, undeclared pointer prefixes, and archival best practice.
Ships in tei-validator. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
scripts/validate_tei.py checks TEI P5 files in three layers:
TEI or teiCorpus root in the TEI
namespace. It needs a teiHeader with titleStmt/title, publicationStmt and sourceDesc, then a
text with a body or group. A record that has only page images (facsimile or sourceDoc) is
also accepted.tei_all.rng schema, run with xmllint. This catches wrong element
names, wrong nesting and wrong attribute values. The schema (about 1 MB) is downloaded once and cached.#id links that point nowhere;xml:id values;@from after @to;cbdb:1234 with no <prefixDef>;<rs> with no @type;It uses only the Python standard library. xmllint is part of libxml2: it comes with macOS, and on
Debian or Ubuntu it is installed with apt install libxml2-utils. Without xmllint, layers 1 and 3
still run, and the report says that the schema was not checked.
local-ocr or multi-agent-vision-ocr, entity annotation, or conversion scripts.@when-custom.It does not check whether the text matches the source. It does not check whether an external URI
resolves. It does not check a project's own ODD rules unless you pass that project's schema with --schema.
Find the files. One file, several files, or a folder. A folder means every *.xml file inside
it, including subfolders.
Pick the level.
| Level | What it checks | Use |
|---|---|---|
basic | XML, namespace, required structure | quick syntax check |
standard (default) | + TEI schema, names, dates, links, ids | normal check |
strict | + best practice (encodingDesc, revisionDesc, authority links, entity lists) | before publishing |
Run it.
python3 scripts/validate_tei.py edition/ --strict
The first run downloads the schema. Each run spends about 8 s reading the schema. A whole folder is
checked in one xmllint call, so check folders, not files one by one.
Read the report. Each problem has a code, a line number, the element and a suggested fix. The file is VALID when there are no ERRORs. Warnings and INFO do not change the exit code.
Fix and run again. The codes are explained in
references/validation-rules.md. Fix the schema errors (SCHEMA001)
first: one nesting mistake can cause several follow-on errors.
| Option | Meaning |
|---|---|
--level basic|standard|strict | how much to check (--strict = --level strict) |
--schema PATH | use your own RelaxNG schema (for example one made from a project ODD) instead of tei_all.rng |
--no-schema | skip the schema check (offline, or no xmllint) |
--update-schema | download tei_all.rng again (new TEI release) |
--json | print JSON (one object for one file, a list for several) |
--report FILE | also write the text report to a file |
--quiet | show errors only |
Exit code: 0 if all files are valid, 1 if any file has an error, 2 if no XML files were found.
--strict before you publish. standard is enough while you work.<p> inside a <p>,
are only found by the schema.@when when the
Gregorian date is known, or @when-custom with @datingMethod when it is not. Convert dates with the
cjk-calendar skill. Do not put a lunar date in @when: @when is always a Gregorian date.ref="cbdb:30374" are good TEI, but declare the prefix once in
encodingDesc/listPrefixDef. Otherwise other tools cannot expand it (REF003).--json and count them by
code to see the pattern.# one file
python3 scripts/validate_tei.py letter.xml
# a folder, strict, JSON for a script
python3 scripts/validate_tei.py edition/ --strict --json > validation.json
# a project schema made from an ODD
python3 scripts/validate_tei.py edition/ --schema myproject.rng
import sys
sys.path.insert(0, "scripts")
from validate_tei import TEIValidator
v = TEIValidator(level="strict") # schema=PATH, use_schema=False also work
for r in v.validate_many(["a.xml", "b.xml"]):
print(r.file, "valid" if r.is_valid else "INVALID", r.schema)
for e in r.errors:
print(f" {e.code} line {e.line}: {e.message}")
A minimal valid file:
<TEI xmlns="http://www.tei-c.org/ns/1.0">
<teiHeader><fileDesc>
<titleStmt><title>崇禎十年家書</title></titleStmt>
<publicationStmt><p>Unpublished transcription</p></publicationStmt>
<sourceDesc><p>Manuscript letter, private collection</p></sourceDesc>
</fileDesc></teiHeader>
<text><body>
<p><date when-custom="崇禎十年" datingMethod="#chongzhen">崇禎十年</date>
<persName ref="https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=30374">王守仁</persName></p>
</body></text>
</TEI>
tei_all schema: https://tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rngReport a problem. This skill is part of the public repository kltng/humanities-skills. If it fails (an API changed, a script errors, or these instructions are wrong), report it as a GitHub issue:
gh issue list --repo kltng/humanities-skills --state all --search "tei-validator"gh issue create --repo kltng/humanities-skills --label bug --title "[tei-validator] <short summary>" --body "<details>". Without gh, give the user this link: https://github.com/kltng/humanities-skills/issues/new?template=skill-problem.ymlCredit the source. The schema and the rules behind this skill are the work of the TEI Consortium (https://tei-c.org). The tei_all.rng schema and the TEI Guidelines are under two licences, CC BY 3.0 and BSD 2-Clause. The Consortium asks for this citation of the Guidelines:
TEI Consortium, eds. TEI P5: Guidelines for Electronic Text Encoding and Interchange. [Version number]. [Last modified date]. TEI Consortium. https://www.tei-c.org/guidelines/p5/ ([Date of access]).
The version number and date are at the top of the cached schema file. The schema check is run by xmllint, part of libxml2 (Daniel Veillard and the libxml2 contributors).
Cite. If this skill helped work that is published, please cite it, together with the source credited above:
Tang, Kwok-leong. humanities-skills: tei-validator (version ). GitHub, . https://github.com/kltng/humanities-skills
When you help a user write up results that relied on this skill, remind them once about this citation and the credit above.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
/tei-validator:tei-validatorfrom tei-validator
npx claudepluginhub kltng/humanities-skills --plugin tei-validatorOther plugins' skills for the same job