madbot_cli.checks
Check a deposit file against the schemas the instance publishes, before any write.
madbot checks on write the shared parameters and the credentials of a
connection, the settings of a submission and each metadata value. It
publishes the schema of each: plan and apply check the file against them
first, so that every value madbot would refuse is reported at once, with what
it expects, instead of one by one in the middle of an apply.
madbot stays the judge: a format the client cannot check offline, such as an ORCID or a taxon looked up in a referential, is left to madbot.
Credentials never appear in a message: only their keys and the form the plugin expects.
Attributes
| Name | Description |
|---|---|
CLOSEST | How many close values a message proposes. |
FORMATS | What a format of JSON Schema asks for, in words. |
FORMAT_CHECKER | The formats checked offline; madbot checks the others itself. |
SHOWN_CHOICES | How many allowed values a message lists, at most. |
TYPES | What a type of JSON Schema asks for, in words. |
Classes
| Name | Description |
|---|---|
CheckError | The file gives values madbot would refuse. |
Schemas | The schemas and the fields the instance publishes, read once per command. |
Functions
| Name | Description |
|---|---|
check | Check a deposit file against the schemas the instance publishes. |
check_connection | Check the shared parameters and the credentials of a source or a repository. |
check_metadata | Check each metadata value of a submission against the schema of its field. |
check_params | Check the parameters of a connection against those of its plugin. |
check_settings | Check the settings of a submission to create against those of its repository. |
check_submission | Check the repository, the settings and the metadata of a submission. |
check_value | Check a value against its schema, as madbot does on write. |
closest | Find the allowed values closest to a value, by their text or their title. |
deepest | Follow an error of forms to the error of the form closest to the value. |
described | Describe the parameters a plugin expects, with their values. |
expected | Say in words what a schema accepts. |
expected_across | Say in words what a part expects, in each form of the object that has it. |
explain | Say what is wrong with a value and what is expected instead. |
key_of | Return the key a schema address stands for. |
listed | Write values in a sentence, cut when they are many. |
metadata_values | List the values of the metadata of a submission, with where they are. |
object_parts | List the parts of an object a metadata field holds, to write it with its keys. |
parameters | Read the schemas of the parameters of a plugin, by key. |
plugin_hint | Name the discovery command that describes a plugin. |
require | Stop when the file gives values madbot would refuse. |
unnamed_form | Say which part of an object names its form, when the value names none. |
unquoted_date | Find a date YAML read from an unquoted value, such as 2026-11-02. |
variant_of | Choose the form of a schema a value names by its fixed parts. |
CLOSESTattributemodule attribute#
CLOSEST = 3How many close values a message proposes.
FORMATSattributemodule attribute#
FORMATS = {
'date': 'a full date, YYYY-MM-DD',
'date-time': 'a date and a time, YYYY-MM-DDThh:mm:ss',
'time': 'a time, hh:mm:ss',
'email': 'an email address'
}What a format of JSON Schema asks for, in words.
FORMAT_CHECKERattributemodule attribute#
FORMAT_CHECKER = jsonschema.Draft201909Validator.FORMAT_CHECKERThe formats checked offline; madbot checks the others itself.
SHOWN_CHOICESattributemodule attribute#
SHOWN_CHOICES = 5How many allowed values a message lists, at most.
TYPESattributemodule attribute#
TYPES = {
'string': 'a text',
'integer': 'a whole number',
'number': 'a number',
'boolean': 'true or false',
'object': 'an object (key: value)',
'array': 'a list',
'null': 'nothing'
}What a type of JSON Schema asks for, in words.
CheckErrorclass#
class CheckError(errors: list[str])Bases: MadbotError
The file gives values madbot would refuse.
Attributes
| Name | Type | Description |
|---|---|---|
errors | list of str | One message per value, each starting with where it is in the file. |
Parameters
| Name | Type | Description |
|---|---|---|
errors | list of str | One message per value. |
Schemasclass#
class Schemas(client: Client)The schemas and the fields the instance publishes, read once per command.
fieldsmethod#
def fields(source: str) -> dict[str, list[dict]]List the metadata fields of a plugin, by slug.
Parameters
| Name | Type | Description |
|---|---|---|
source | str | The slug of the plugin. |
Returns
dict- The fields of each slug, as the API returns them.
schemamethod#
def schema(url: str) -> dictRead a schema, its definitions put in place.
Parameters
| Name | Type | Description |
|---|---|---|
url | str | Its address, as the API gives it. |
Returns
dict- The schema.
checkfunction#
def check(client: Client, state: State, manifest: Manifest, environ: Mapping[str, str] | None = None) -> list[str]Check a deposit file against the schemas the instance publishes.
Only what apply would write is checked: a connection madbot holds keeps its parameters, and the metadata of a submission already sent to its repository cannot change.
Parameters
Returns
list of str- One message per value madbot would refuse; empty when there is none.
check_connectionfunction#
def check_connection(schemas: Schemas, plugins: list[dict], spec: Mapping[str, Any], where: str, planned: Mapping, environ: Mapping[str, str] | None = None) -> list[str]Check the shared parameters and the credentials of a source or a repository.
The shared parameters are checked when the connection is to be created: one madbot holds has them already. The credentials are checked when apply would send them.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
schemas | Schemas | required | The schemas of the instance. |
plugins | list of dict | required | The plugins of the instance. |
spec | mapping | required | plugin, shared_params and credentials_env from the file. |
where | str | required | Where it is in the file, such as sources.reads. |
planned | mapping | required | The plan of the connection, with its action and credentials. |
environ | mapping | None | The environment holding the credentials. |
Returns
list of str- One message per error.
check_metadatafunction#
def check_metadata(schemas: Schemas, plugin: Mapping, metadata: Mapping[str, Any], where: str) -> list[str]Check each metadata value of a submission against the schema of its field.
Parameters
Returns
list of str- One message per value madbot would find invalid, that YAML read as a date, or given for no field of the repository: madbot would refuse the whole write, and a typo would leave the value unwritten.
check_paramsfunction#
def check_params(known: Mapping[str, Mapping], given: Mapping[str, Any], where: str, plugin: Mapping, *, secret: bool = False) -> list[str]Check the parameters of a connection against those of its plugin.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
known | mapping | required | The schema of each parameter of the plugin, by key. |
given | mapping | required | The parameters of the file, or the credentials. |
where | str | required | Where they are, in the messages. |
plugin | mapping | required | The plugin. |
secret | bool | False | True for credentials: no message shows a value. |
Returns
list of str- One message per key unknown, missing or of a value madbot refuses.
check_settingsfunction#
def check_settings(schemas: Schemas, plugin: Mapping, settings: Mapping[str, Any], where: str) -> list[str]Check the settings of a submission to create against those of its repository.
Parameters
Returns
list of str- One message per setting unknown, missing while mandatory, or of a value madbot refuses.
check_submissionfunction#
def check_submission(schemas: Schemas, state: State, submission: Submission, environ: Mapping[str, str] | None = None) -> list[str]Check the repository, the settings and the metadata of a submission.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
schemas | Schemas | required | The schemas of the instance. |
state | State | required | What madbot holds. |
submission | Submission | required | The submission. |
environ | mapping | None | The environment holding the credentials. |
Returns
list of str- One message per error.
check_valuefunction#
def check_value(schema: Mapping, value: Any, *, secret: bool = False) -> list[str]Check a value against its schema, as madbot does on write.
Parameters
Returns
list of str- What is wrong, empty when the value is valid.
closestfunction#
def closest(value: Any, choices: Iterable[Mapping]) -> list[str]Find the allowed values closest to a value, by their text or their title.
Parameters
| Name | Type | Description |
|---|---|---|
value | Any | The value given. |
choices | iterable of mapping | The allowed values, as madbot_cli.discover.choices_of gives them. |
Returns
list of str- At most
CLOSESTvalues, the closest first.
deepestfunction#
def deepest(error: jsonschema.ValidationError) -> jsonschema.ValidationErrorFollow an error of forms to the error of the form closest to the value.
Parameters
| Name | Type | Description |
|---|---|---|
error | ValidationError | An error, maybe of oneOf or anyOf. |
Returns
ValidationError- The error to explain. An error of forms whose forms are only fixed values stays as it is: its message is the list of values.
describedfunction#
def described(known: Mapping[str, Mapping]) -> strDescribe the parameters a plugin expects, with their values.
Parameters
| Name | Type | Description |
|---|---|---|
known | mapping | The schema of each parameter, by key. |
Returns
str- Such as
url: one of https://a or https://b; token: a text.
expectedfunction#
def expected(schema: Mapping) -> strSay in words what a schema accepts.
Parameters
| Name | Type | Description |
|---|---|---|
schema | mapping | The JSON Schema of a value. |
Returns
str- Such as
one of a or b,a full date, YYYY-MM-DD, ora text.
expected_acrossfunction#
def expected_across(found: list[tuple[str, Mapping]]) -> strSay in words what a part expects, in each form of the object that has it.
Parameters
| Name | Type | Description |
|---|---|---|
found | list of tuple | The title of each form that has the part (form 2 when it has
none), with the schema of the part in it. |
Returns
str- What it expects; the fixed values of the forms together, each once,
such as
one of A or B; or else what each form expects, by its title, the forms that expect the same said together.
explainfunction#
def explain(error: jsonschema.ValidationError, *, secret: bool = False) -> strSay what is wrong with a value and what is expected instead.
Parameters
Returns
str- The message, starting with the part of the value when it is inside it.
key_offunction#
def key_of(url: str) -> strReturn the key a schema address stands for.
Parameters
| Name | Type | Description |
|---|---|---|
url | str | The address of the schema of a parameter or a setting. |
Returns
str- Its last part, which the API builds from the slug.
listedfunction#
def listed(values: Iterable[Any], limit: int = SHOWN_CHOICES) -> strWrite values in a sentence, cut when they are many.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
values | iterable | required | The values. |
limit | int | SHOWN_CHOICES | How many are written. |
Returns
str- Such as
a, b or c, ora, b, c… (12 values).
metadata_valuesfunction#
def metadata_values(metadata: Mapping[str, Any]) -> Iterable[tuple[str, str, Any]]List the values of the metadata of a submission, with where they are.
Parameters
| Name | Type | Description |
|---|---|---|
metadata | mapping | The metadata of a submission in the file. |
Yields
tuple- Where the value is (such as
metadata.sample.by_alias.s1.r__date), the slug of its field, and the value without its empty parts. An empty value is left out: apply writes nothing for it.
object_partsfunction#
def object_parts(schema: Mapping) -> list[dict]List the parts of an object a metadata field holds, to write it with its keys.
A field of several forms, all objects (such as an instrument of one form per platform), gives every key of its forms; a part that differs from a form to another says what each form expects.
Parameters
| Name | Type | Description |
|---|---|---|
schema | mapping | The JSON Schema of the field. |
Returns
list of dict- Each part with its
key, whether every formrequiredit, and what itexpected, in words. Empty when the field is not an object, or may be something else than an object (such as a date).
parametersfunction#
def parameters(schemas: Schemas, urls: Iterable[str]) -> dict[str, dict]Read the schemas of the parameters of a plugin, by key.
madbot checks {key: value} against the schema of each key. A schema
holding several keys is split, one object schema per key.
Parameters
| Name | Type | Description |
|---|---|---|
schemas | Schemas | The schemas of the instance. |
urls | iterable of str | The addresses of the schemas, as the plugin gives them. |
Returns
dict- The schema of each parameter by its key: an object holding that key, required when its schema requires it.
plugin_hintfunction#
def plugin_hint(plugin: Mapping) -> strName the discovery command that describes a plugin.
Parameters
| Name | Type | Description |
|---|---|---|
plugin | mapping | The plugin, as the API returns it. |
Returns
str- Such as “see `madbot-cli plugins ena```.
requirefunction#
def require(client: Client, state: State, manifest: Manifest, environ: Mapping[str, str] | None = None) -> NoneStop when the file gives values madbot would refuse.
Parameters
Raises
CheckError- With every value madbot would refuse.
unnamed_formfunction#
def unnamed_form(error: jsonschema.ValidationError, *, secret: bool = False) -> str | NoneSay which part of an object names its form, when the value names none.
The forms of a field are told apart by a fixed part, such as
library_layout set to single or paired. A value naming no
form fails every form; the error of the first one alone, 'single' was expected, would hide the others.
Parameters
unquoted_datefunction#
def unquoted_date(value: Any) -> datetime.date | NoneFind a date YAML read from an unquoted value, such as 2026-11-02.
Parameters
| Name | Type | Description |
|---|---|---|
value | Any | A metadata value of the file. |
Returns
datetime.date or None- The first date or date and time found in the value, or None.
variant_offunction#
def variant_of(schema: Mapping, value: Any) -> MappingChoose the form of a schema a value names by its fixed parts.
An instrument {platform: X, model: …} is checked against the form of
platform X, so that the message is about its model, not about every form.
Parameters
| Name | Type | Description |
|---|---|---|
schema | mapping | A JSON Schema, with oneOf or anyOf forms or without. |
value | Any | The value. |
Returns
mapping- The form named, merged with the rest of the schema; the schema itself when the value names no single form.

