Skip to content

17. Working with AI (MaiML, vocabularies, schemas, ELN entries) ​

MaiML mappings, vocabularies, metadata schemas and ELN entries all take effort to write from scratch. Letting an AI draft them is fast, but AI mixes in plausible mistakes (IRIs that do not exist, random uuids, wrong units). This chapter describes a workflow where the AI drafts and machines and people check. The BENTEN MaiML (XAFS, HAXPES) is used as the example.

Who does what ​

WhoDoesIn this toolkit
AIDrafts (mappings, term candidates, the schema Excel, proposed edits)Claude Code, Claude Desktop (chapter 16)
MachineChecks structure and linksmaiml check (chapter 10), benten_schema check, schema validation (chapter 15), the VS Code XML and YAML extensions
PeopleDecide meaning and what may be publishedHow terms map (exactMatch or broadMatch), which terms to add, the publication tags

Treat AI output as a draft until it passes the machine checks. Even then, people decide whether the meaning is right.

Build vocabularies on existing ones ​

Every facility needs a "local dictionary" of techniques, detection modes, sample forms and materials. Building one from scratch means owning every definition, alias, translation and mapping yourself, which rarely lasts. Start from an existing vocabulary and add only what is missing (the "+α"). AI is good at finding what is missing and proposing candidates.

BaseCoversWhat BENTEN added (+α)
PaNET (photon and neutron techniques)XAFS, EXAFS, XANES, HAXPES, …Detection modes (transmission, fluorescence, TEY, CEY) mapped to PaNET; how XAFS relates to PaNET01197
MatVoc (NIMS materials vocabulary)Materials, elements, energy levelsA materials vocabulary with IDs and URIs for SPring-8 samples not in MatVoc; a dictionary of spelling variants (supplier names, middle dots in formulas, purity such as 3N); sample forms (powder, foil, lump, …)

PaNET + α: map missing terms to a nearby term, with a strength ​

PaNET has no term for transmission mode or conversion electron yield (CEY). Instead of inventing new terms, keep the nearest PaNET term and how close it is.

BENTENPaNETMapping
XAFSPaNET01196 x-ray absorption spectroscopyexactMatch
EXAFSPaNET01198exactMatch
XANESPaNET01199exactMatch
HAXPESPaNET01103exactMatch
Total electron yield (TEY)PaNET01220exactMatch
TransmissionPaNET01227 x-ray absorptionbroadMatch (+α)
FluorescencePaNET01177 x-ray fluorescence-based techniquesrelated (+α)
Conversion electron yield (CEY)PaNET01220broadMatch (+α)

The AI may propose the mapping strength (SKOS exactMatch, closeMatch, broadMatch, related), but people decide it. In MaiML, write the technique as a PaNET IRI (b.uri("ex:technique", "http://purl.org/pan-science/PaNET/PaNET01196"), chapter 10).

Of the 751 materials among BENTEN's raw materials and HAXPES reference samples, 607 were in MatVoc and 144 were not. Do not wait for the missing ones: give them your own ID and URI, use them in MaiML, and list them as proposals for MatVoc. Once MatVoc registers one and it gets a QID, link your term to it with exactMatch. Keep your own ID, so MaiML files already written stay valid.

The MatVoc candidate search was split between machine and people:

  1. Machine: search MatVoc by name and formula and write the candidates with a confidence (high, medium, low) to Excel (nothing is written to the ELN)
  2. People: review the candidates in Excel and correct the "adopted QID" column
  3. Machine: write only the decided QIDs to the ELN, after checking them with a dry run

Make the spelling-variant dictionary part of the +α ​

Before matching, define rules that normalise spelling variants. For BENTEN's 693 raw materials, formula mismatches dropped from 122 to 16.

  • Aliases of supplier names (Japanese and English company names → one id)
  • Remove middle dots and trailing notes such as (rutile) from formulas, and compare element counts
  • Compare purity as numbers (3N = 99.9)

Use the same rules for matching, AI input assistance and MaiML export. If each place keeps its own rules, the same material becomes different things in different places.

Notes on using vocabularies ​

  • Check each vocabulary's terms of use and redistribution (PaNET is CC BY 4.0; BENTEN keeps its MatVoc copy internal and writes only IRIs into MaiML it publishes)
  • Fix the shape of your own URIs before publishing them (BENTEN uses https://support.jasri.jp/benten/vocab/material/<ID>). Changing it later leaves exported MaiML pointing at old URIs

Designing MaiML with AI ​

Ask the AI for a draft of the table below. In BENTEN, the AI produced this table from the ELN fields, people corrected it, and it then became toolkit code.

To decideExample (BENTEN)How to check
ELN field → MaiML key, type, unitAbsorption edge → benten:absorption_edge (the ELN title) and matvoc:edge (the MatVoc URI)maiml check (XSD)
Technique and material termsXAFS → PaNET01196 in panet:technique; raw material → a MatVoc QID or your own IDLook the IRI up (below)
What shares a uuidOne per raw-material item in the ELN; owner, vendor, instrument from role and id (stable_uuid)Export twice and compare the uuids
Parent–child linksRaw-material hub → measured sample (instanceRef) → measurement (<parent> + SHA-256)maiml check (parent-missing, parent-hash, material-differs)

Where AI tends to go wrong ​

MistakeExampleHow to prevent it
Inventing IRIs or QIDsA plausible PaNET0xxxx or MatVoc Q…Look them up, with labels, in the vocabulary copy (PaNET.csv, …) or its API
Calling a near term "the same"Transmission as exactMatch to "x-ray absorption"People decide the strength; when unsure use broadMatch or related
Random uuidsuuid4() gives a new uuid on every export (actually fixed in this toolkit)Derive them from the ELN id with stable_uuid; export twice and compare
Wrong units or typeskeV vs eV, numbers as stringsCheck with the XSD and the schema's units and types
Treating spelling variants as different thingsTwo spellings of one supplier as two suppliersBuild the spelling-variant dictionary first and give it to the AI
Building from scratchDefining every technique term yourselfSay "base it on the existing vocabulary and add only what is missing" up front

How to check ​

CheckHow
The IRI or QID exists and the label matchesPaNET: PaNET.csv / panet.json (copies); MatVoc: https://matvoc.wikibase.cloud/w/api.php (wbgetentities, wbsearchentities)
MaiML structure and linkspython -m elabftw_toolkit.maiml check <folder>; the VS Code XML extension with the MaiML XSD (chapter 10)
A diagram of links across placespython -m elabftw_toolkit.maiml graph <folders…> (Mermaid); the MCP tool maiml_graph (chapter 10)
Metadata matches the schemapython -m elabftw_toolkit.benten_schema check <folder>; the VS Code YAML extension with the JSON Schema from export-jsonschema
ELN writes do what you intendThe dry-run Plan (chapter 15)

If you ask the AI to "run the check commands and fix until there are 0 errors and warnings", the machine checks can be left to the AI. People then look at the remaining warnings and at meaning.

Revising the metadata schema with AI ​

Start from the BENTEN schema Excel (BENTEN metadata and schema) and have the AI adapt it to your instrument.

  1. Give the AI the Excel and your instrument's fields (your current ELN template or your measurement software's output) and ask which columns to add, remove or rename
  2. Correct the proposal and apply it to the Excel, then run python -m elabftw_toolkit.benten_schema lint my_schema.xlsx to catch typos in types and options and examples that do not fit
  3. Convert it with python -m elabftw_toolkit.benten_schema export-jsonschema my_schema.xlsx -o my_metadata.schema.json and check your metadata with check
  4. Decide whether each mismatch is a schema error or a data error

Letting AI help with ELN entries ​

With the MCP server (chapter 16), Claude Desktop can edit the ELN.

  • It only reads by default. Add ELABFTW_ALLOW_WRITE=1 only when you want it to write (put files to attach in ELABFTW_UPLOAD_DIR)
  • When writing, have the AI preview with dry_run=true and show old value → new value before it writes
  • Have it pass reason, so why the entry changed is kept as a comment (the person is ELABFTW_MCP_USER)
  • People decide the publication tags (whether something may go outside). Do not let the AI set them

Example requests ​

Ready-to-use prompts. Replace < > with your own.

Mapping a vocabulary

text
Map the measurement techniques and detection modes used at <instrument> to PaNET terms.
- Do not invent new terms for what PaNET lacks; give the nearest PaNET term and the SKOS mapping (exactMatch / closeMatch / broadMatch / related).
- Use only PaNET IDs that appear in the attached PaNET.csv, and show their labels.
- For anything other than exactMatch, give a one-line reason.

Finding MatVoc candidates

text
For the attached list of raw materials (name, formula, supplier), find MatVoc candidates.
- Actually search the MatVoc API (wbsearchentities) and list only QIDs and labels you found. Do not guess QIDs.
- Mark formula matches as "high" and name-only matches as "medium".
- Mark materials not found as "not in MatVoc" and collect what a proposal needs (English name, formula, CAS).

Drafting the MaiML mapping

text
Turn the fields of the ELN template <template name> into a table of MaiML key, type and unit.
- Do not use random uuids; derive them from the ELN id (elabftw_toolkit.maiml.stable_uuid).
- After exporting, run python -m elabftw_toolkit.maiml check <folder> and fix until there are 0 errors and warnings.

Editing the ELN

text
In items of category <category>, I want purity written as a number such as "99.9".
First show me, with dry_run=true, the entries that would change and old value → new value. After I agree, write them with reason="normalise purity notation".

Apache License 2.0