BENTEN metadata and schema
SPring-8's research data platform BENTEN keeps a metadata file, metadata.all.yml, for every measurement (dataset). BENTEN's standard-sample database (eLabFTW: benten-eln) stores it unchanged as the structured_metadata of each measurement entry. This page explains what it contains, how its keys are written, and how to check it against the BENTEN metadata schema.
You do not need any of this for non-BENTEN data. For structured_metadata in general, see Reading and writing structured_metadata.
Download the schema Excel and adapt it to your own data
benten_metadata_schema-2021.06.07.xlsx (the 150-item BENTEN schema; the README sheet explains the layout). Adding or removing items, changing required items or options, and adding section sheets are covered in Customizing it.
What it contains (an XAFS standard sample)
A BL14B2 XAFS standard: Ag₂O at the Ag K edge (excerpt).
data_info: # identification, rights, facility
identifier:
pid: spring8.424a4139-548c-4a03-8f8b-5f3b447e337b
proposal_number: 2014S0000
register_name: /SPring-8/BL14B2/XAFS_Standard/Ag/K/111/Ag2O
date: {create_time: '2020-01-15 18:51:18', update_time: '2021-03-19 16:34:56'}
access_rights: open
facility: SPring-8
class_name: BL14B2
facility: # storage ring state
ring: {energy: 8.0, energy_unit: GeV, filling_pattern: 203 bunches, start_current: 99.5, start_current_unit: mA}
sample: # samples (an array)
- {chemical_formula: Ag2O, name: Silver(I) oxide, supplier: KOJUNDO CHEMICAL LABORATORY, lot_number: '4050891'}
measurement: # method, edge, detection, date and time
date: {start_time: '2016-04-12 01:57:00', end_time: '2016-04-12 02:01:00'}
method: {category: spectroscopy, sub_category: XAFS, absorption_edge: Ag K-edge, detection: Transmission( 2)}
instrument: # monochromator, slits, detectors
monochrometer: {net_plane: Si(111), distance: 3.13551, distance_unit: A}
slit:
- {name: 4Dslit, vertical_size: 1.0, vertical_size_unit: mm, horizontal_size: 5.0, horizontal_size_unit: mm}
xafs:
I0:
element: [{type: Ion Chamber, gas: Ar 100%, HV: 1000.0, HV_unit: V}]
local: # facility-specific items (outside the schema)
measurement_time: 267.0
measurement_time_unit: sec
xafs_filename_list: [Ag-K_Ag2O_Si111_50ms_160412.dat]| Section | Contents |
|---|---|
data_info | PID, proposal number, registered name, dates, access rights, facility and beamline, depositor |
facility | Ring energy, current, filling pattern |
sample | Formula, name, supplier, model number, lot (an array; there may be several samples) |
measurement | Method (XAFS, HAXPES), absorption edge or photoelectron lines, detection, date and time |
instrument | Monochromator crystal, slits, detectors (XAFS: xafs.I0 / I1 / I2) |
dataset | File lists and captions |
local | Facility-specific items not in the schema (measurement time, meaning of raw-data columns, ...) |
monochrometer is spelled as in the schema.
Three ways to write a key
| Notation | Example | Where |
|---|---|---|
| BENTEN Key name | @sample.chemical_formula | BENTEN's schema Excel; @ = dict, . = array element |
| @ key (with indices) | @sample.0@chemical_formula | entry body tables, flatten_at() output |
| schema path | sample[].chemical_formula | toolkit schema, path of check results |
from elabftw_toolkit import benten_schema as bs
bs.key_to_path("@sample.chemical_formula") # Key name → path: "sample[].chemical_formula"
bs.path_of("@sample.0@chemical_formula") # @ key → path: "sample[].chemical_formula"
rows = bs.flatten_at(md) # nested → list of @ keys
md2 = bs.unflatten_at(rows) # list of @ keys → nestedThe BENTEN metadata schema
The BENTEN schema (metadata_schema-2021.06.07.xlsx) exported to JSON ships with the toolkit (elabftw_toolkit/data/benten_schema.json, 150 items).
| Type | Items | Values |
|---|---|---|
keyword / text | 69 / 29 | strings |
double | 23 | numbers |
integer / long | 6 / 1 | integers |
date | 6 | date or date-time strings such as 2016-04-12 01:57:00 |
array | 16 | lists (sample, instrument.slit, ...) |
Seven items are required (Option = required), all in data_info: the proposal number (identifier.proposal_number), the data origin (data_origin), access rights (access_rights: open / close), the depositor's name and affiliation, and the contact's name and affiliation. The original BENTEN tools filled data_origin with experiment when it was empty, so a missing one is not reported.
One obvious mistake in the Excel is fixed on load: @instrument@xafs@I2@element.amp_gain is typed text (I0 and I1 are double, and the values are numbers), so it is read as double. load_schema(raw=True) keeps it as it is.
Checking
schema = bs.load_schema()
md = elab.experiments.entry(1563).metadata.structured()
problems = bs.validate(md, schema)
ok = all(p["kind"] == "local" for p in problems) # pass when there is nothing but "local"Checking the 2,282 published XAFS standards found nothing but local items (5 items, allowed), except one dataset:
[type] measurement.date.start_time date: not a date value '2016-06-24 05:4:00'
measurement.date.end_time date: not a date value '2016-06-24 05:5:00'
e.g. …/XAFS_Standard/Ag/K/311/Ag2WO4/metadata.all.ymlThe minutes have one digit (05:4:00), so the value is not a valid date — the kind of error that is easy to miss by eye.
How YAML is read, and what only check finds
check reads YAML the way VS Code's YAML extension does (YAML 1.2), so the command line and the editor agree. PyYAML's common yaml.safe_load (YAML 1.1) reads these values differently:
| Written | check, VS Code (YAML 1.2) | yaml.safe_load (YAML 1.1) |
|---|---|---|
create_time: 2023-02-03 | the string "2023-02-03" (no quotes needed) | a date value |
access_rights: yes (also no, on, off) | the string "yes" | True |
name: 0123 | the integer 123 | 83 (read as octal) |
time: 1:30 | the string "1:30" | 90 (read as base 60) |
Some problems cannot be written in JSON Schema, so VS Code does not show them and only check reports them:
| Problem | Example | Kind |
|---|---|---|
| A date that does not exist | 2023-02-30 (the shape is right) | type (date does not exist) |
| A key written twice | access_rights: twice in one mapping; YAML keeps only the last one and the first value silently disappears | duplicate |
With --lines, each problem is one line with the file and line number (the form the VS Code task below reads):
python -m elabftw_toolkit.benten_schema check <folder or metadata.all.yml> --lines
# C:\…\metadata.all.yml:5:1: error: 重なったキー: data_info.access_rights キー 'access_rights' が重なっている(後のほうだけが読まれる) [duplicate]From Python, bs.check_files([...], schema) gives each problem a file and a line; bs.load_yaml(text) reads YAML by the same rules.
The schema in Excel and JSON
The schema Excel has one sheet per section (data_info, facility, sample, measurement, instrument, dataset, system), one item per row, with these columns (row 1 is the header):
| Column | Contents |
|---|---|
| A | Key name (@sample.chemical_formula) |
| B | Option (required / optional / automatic) |
| C | Data type (keyword, text, double, integer, long, date, array) |
| D, E | Description (Japanese, English) |
| F, G | Example, misc |
| H | Enum (comma-separated options) |
| I | Scope |
Export it to JSON to use it where Excel cannot be read (a server, for example):
python -m elabftw_toolkit.benten_schema export-json metadata_schema-2021.06.07.xlsx -o benten_schema.json
python -m elabftw_toolkit.benten_schema export-xlsx -o benten_schema.xlsx # bundled JSON back to Excel
python -m elabftw_toolkit.benten_schema check <folder or metadata.all.yml> --xlsx result.xlsx # check, results in ExcelThere is also a separate XAFS schema compiled in 2023 (metadata_schema-xafs.xlsx, 218 items), but it is organized differently (only 17 items overlap); current BENTEN data follows the 2021 schema on this page.
Checking in VS Code (while you write)
When you write or edit metadata.all.yml by hand, give VS Code's YAML extension a JSON Schema and it checks as you type:
- hover over a key to see its description (Japanese and English) and whether it is required
- wrong types, values outside the options, unknown keys, and missing required items are underlined
Ctrl+Spacecompletes keys and options (open / close foraccess_rights, ...)
1. Install the YAML extension
In Extensions (Ctrl+Shift+X), search for "YAML" and install YAML by Red Hat (redhat.vscode-yaml).
2. Get a JSON Schema
| File | Checks |
|---|---|
| benten_metadata.schema.json (strict) | Types, and keys that are not in the schema (anything goes under local:); empty values only for optional items. For curated data such as standards |
| benten_metadata.loose.schema.json (loose) | Numbers and strings are not told apart; unknown keys and empty values are allowed; required items, options and array shapes are still checked. For work in progress |
Both are made from the bundled BENTEN schema. From a customized schema:
python -m elabftw_toolkit.benten_schema export-jsonschema my_schema.xlsx -o my_metadata.schema.json
python -m elabftw_toolkit.benten_schema export-jsonschema my_schema.xlsx -o my_metadata.loose.schema.json --loose3. Associate it with your YAML files
There are three ways; one is enough.
| Way | Where | Good for |
|---|---|---|
| Per folder | .vscode/settings.json in the working folder | writing or fixing many files in one folder |
| Your whole PC | your user settings.json | always using the same schema |
| Per file | the first line of the YAML | a single file, or a file you hand to others |
Per folder: create .vscode/settings.json in the working folder (the path is relative to the folder):
{
"yaml.schemas": {
"./benten_metadata.schema.json": ["metadata.all.yml", "metadata.*.yml"]
}
}Trust the folder
VS Code does not read .vscode/settings.json in a folder it does not trust (Restricted Mode shows at the bottom left). Click Restricted Mode and choose Trust. The user settings and the first-line comment work without trust.
Your whole PC: in the settings.json opened with Ctrl+Shift+P → "Preferences: Open User Settings (JSON)" (use a full path):
{
"yaml.schemas": {
"C:/Users/<you>/schemas/benten_metadata.schema.json": ["metadata.all.yml", "metadata.*.yml"]
}
}Per file: put this on the first line (the path is relative to the YAML file):
# yaml-language-server: $schema=./benten_metadata.schema.json
data_info:
identifier:
pid: spring8.…
Once associated, the schema name (Metadata schema (…)) shows above (or below) the first line and at the right of the status bar.
4. Reading the screen
This is the example metadata.all.yml with four deliberate errors: a value not among the options (opn), a non-number (99.5 mA), a malformed date (2016-04-12 1:57) and a key not in the schema (colour).

- Errors get a red squiggle and the count shows at the bottom left (ⓧ 4). Your own items under
local:are not flagged. Ctrl+Shift+Mopens the Problems list, with the item's (Japanese) name and the line number; click one to jump to it.

| Message | Meaning (check kind) |
|---|---|
Value is not accepted. Valid values: … | value not among the options (enum) |
Incorrect type. Expected … | wrong type (type) |
String does not match the pattern … | malformed date (type; use 2016-04-12 or 2016-04-12 01:57:00; months 01–12 and hours 00–23 are checked too) |
Property … is not allowed. | key not in the schema (unknown); put facility-specific items under local: |
Missing property "…". | required item missing (required); the squiggle is on the parent key (e.g. data_info:) |
Descriptions: hover over a key to see the item name (Japanese), the English description, the schema's Key name with whether it is required and its type, the supplement (Misc), the allowed values and an example.

Completion: clear a value and press Ctrl+Space to list the allowed values; at a key position it lists keys you have not written yet.

5. Calling check from a task
To get dates that do not exist and keys written twice into VS Code's Problems list as well, run check --lines as a task. Put this in .vscode/tasks.json in your working folder and run it with Ctrl+Shift+P → "Tasks: Run Test Task".
{
"version": "2.0.0",
"tasks": [
{
"label": "BENTEN: check metadata",
"type": "process",
"command": "C:/Users/<name>/miniconda3/envs/elabftw/python.exe",
"args": ["-m", "elabftw_toolkit.benten_schema", "check", "${workspaceFolder}", "--lines"],
"problemMatcher": {
"owner": "benten",
"fileLocation": "absolute",
"pattern": {
"regexp": "^(.+?):(\\d+):(\\d+): (error|warning|info): (.*)$",
"file": 1, "line": 2, "column": 3, "severity": 4, "message": 5
}
},
"group": { "kind": "test", "isDefault": true },
"presentation": { "reveal": "silent" }
}
]
}Add --schema my_schema.xlsx to check against your customized schema. Items under local: show as info. It has the same form as the MaiML task, so both can sit in one tasks.json.
Which to use when
| When | With | You get |
|---|---|---|
| While writing | VS Code (JSON Schema) | Problems in one file, on the spot |
| After saving | The VS Code task (check --lines) | The above plus dates that do not exist and keys written twice (with line numbers) |
| Before registering, in bulk | check (or the MCP tool validate_structured_metadata) | Problems across many files grouped by kind and item, an Excel report, the list of local items |
The strict schema gives the same results as check on the published XAFS standards (only the one date error). JSON Schema cannot summarize or list the items allowed as local, so do the final check with check.
The JSON Schema is written as Draft 2020-12 but uses only keywords that mean the same in Draft 7, so editors that only know Draft 7 check it the same way.
Example files
These are what we used when checking BENTEN's published data (BL14B2 XAFS standards).
| File | Contents |
|---|---|
| benten_metadata_schema-2021.06.07.xlsx | The BENTEN schema (rebuilt from the bundled JSON with export-xlsx; 150 items, one sheet per section plus a README; a starting point for your own) |
| benten_schema_check_example.xlsx | Check results in Excel (29 datasets under Ag/K/311; shows the one date error) |
| metadata.all.yml | One of the checked metadata.all.yml files (Ag₂O, Ag K edge; the depositor's name is removed) |
| benten_metadata.schema.json, loose | JSON Schemas for VS Code (strict, loose; Checking in VS Code) |
The results workbook has four sheets:
| Sheet | What to look at |
|---|---|
| まとめ (summary) | Schema used, fixes applied on load, number of files, counts per kind of problem |
| 問題の一覧 (problems) | One row per kind and item: how many datasets, frequent values, an example file |
| 詳細 (details) | One row per problem (which value in which file); filter it to find what to fix |
| スキーマ (schema) | Every item of the schema used (path, Key name, required, type, options, description) |
To make the same file (with the Ag/K/311 folder at hand):
python -m elabftw_toolkit.benten_schema check XAFS_Standard/Ag/K/311 --xlsx benten_schema_check_example.xlsxCustomizing it
Starting from the BENTEN schema, you can build a schema for your facility, instrument, or lab.
Download the schema Excel and save it under a new name (e.g.
my_schema.xlsx).Edit it:
To Do Add an item Add a row to that section's sheet (Key name, Option, Data type; descriptions optional) Drop an item you do not use Delete the row (data that still has the key is reported as unknown; keeping it asoptionalalso works)Make an item required or optional Set Option to required/optionalFix the allowed values List them in Enum, comma separated (e.g. transmission, fluorescence, TEY)Add a section Add a sheet with the same header row as the others (A1 = Key name); the sheet name becomes the top-level keyFree facility-specific items Leave them out of the schema and put them under local:in the data (allowed aslocal)Check the schema Excel itself (
lint):bashpython -m elabftw_toolkit.benten_schema lint my_schema.xlsxFinding Example A Key name used twice two rows with the same Key name (only the first is used) An unknown Data type or Option typos such as strinorrequirdAn example that does not fit the type or the enum valueas the example of a double item, an example not in the EnumKeys under a plain value items added under a keyword item The bundled BENTEN schema has 2 findings (the duplicate
@facility@ring@filling_pattern_modeand the examplevalueof@instrument@monochrometer@section.dwell_time). Both are as in the original Excel and do not affect checking. Run this first when an AI has edited your Excel, too (17. Working with AI).Check your data:
bashpython -m elabftw_toolkit.benten_schema check <folder or metadata.all.yml> --schema my_schema.xlsx --xlsx result.xlsxTo check while writing in VS Code, also make a JSON Schema (Checking in VS Code).
For servers or MCP, convert it to JSON (no openpyxl needed to read it):
bashpython -m elabftw_toolkit.benten_schema export-json my_schema.xlsx -o my_schema.jsonPass it to the MCP server with
ELABFTW_SM_SCHEMA, or in Python withload_schema("my_schema.json").
Type names: keyword, text, string (strings), double (number), integer, long (integers), date, array. The type fix for @instrument@xafs@I2@element.amp_gain and treating a missing data_info.data_origin as present are BENTEN-specific rules; they only apply when those items exist.
How benten-eln uses it
- The measurements (experiments "XAFS標準試料測定" and "HAXPES標準試料測定") hold
metadata.all.ymlas structured_metadata. For XAFS,data_info.license.nameis set toCC BY 4.0on registration. - The entry body shows the same content as tables of @ keys (collapsed per section).
- benten-cloud's intake tool (
intake/intake.py) and export (builder/export_from_eln.py) check against this schema too. - benten-cloud's MCP server (
eln/mcp_server.py) handles it withget_structured_metadata,validate_structured_metadata, andset_structured_metadata. You can ask: "Before putting this metadata.all.yml into measurement 101, check it against the BENTEN schema."
What to read next
- Reading and writing structured_metadata: reading, writing, conversion, your own schema
- 16. MCP server: working with the ELN from AI assistants
- How MaiML export works: build MaiML from fields and attachments