Skip to content

Validation

Validation of configuration.

validate_config

validate_config(config, schema, config_type)

Validate configuration.

NB - This will fail on raw YAML files, the configuration should be passed through clean_config() first to convert configuration values to their expected types.

Parameters:

Name Type Description Default
config dict

Config dictionary imported by read_yaml() and parsed through clean_config().

required
schema Schema

A schema against which the configuration is to be compared.

required
config_type str

Description of of configuration being validated.

required
Source code in src/layopt/validation.py
def validate_config(config: dict[str, Any], schema: Schema, config_type: str) -> None:
    """
    Validate configuration.

    NB - This will fail on raw YAML files, the configuration should be passed through ``clean_config()`` first to
    convert configuration values to their expected types.

    Parameters
    ----------
    config : dict
        Config dictionary imported by ``read_yaml()`` and parsed through ``clean_config()``.
    schema : Schema
        A schema against which the configuration is to be compared.
    config_type : str
        Description of of configuration being validated.
    """
    try:
        schema.validate(config)
        logger.info(f"✅ The {config_type} configuration is valid.")
    except SchemaWrongKeyError:
        raise
    except SchemaError as schema_error:
        msg = (
            f"❌ There is an error in your {config_type} configuration. "
            "Please refer to the first error message above for details"
        )
        raise SchemaError(msg) from schema_error