Skip to content

Config Model

Base model for configuration schemas that report invalid options as component configuration errors.

ConfigErrorModel(**data)

Bases: BaseModel

Pydantic model whose construction and validation raise ComponentConfigError instead of ValidationError.

The constructor, model_validate, and model_validate_json all translate pydantic validation errors, so a configuration loaded from a dict or JSON fails the same way as one built with keyword arguments.

Attributes:

Name Type Description
config_component ClassVar[str]

Name of the component named in the error message.

config_subject ClassVar[str]

Description of the options named in the error message.

config_parameter ClassVar[str]

Parameter named when the error has no field location.

config_operation ClassVar[str]

Allowlisted diagnostic operation of the error.

Initialize the configuration, reporting invalid options as a component configuration error.

Parameters:

Name Type Description Default
**data Any

Configuration options.

{}

Raises:

Type Description
ComponentConfigError

If an option is invalid.

model_validate(obj, **kwargs) classmethod

Validate an object as this configuration, reporting invalid options as a component configuration error.

Parameters:

Name Type Description Default
obj Any

The object to validate, such as a dict of options.

required
**kwargs Any

Keyword arguments passed to BaseModel.model_validate.

{}

Returns:

Name Type Description
Self Self

The validated configuration.

Raises:

Type Description
ComponentConfigError

If an option is invalid.

model_validate_json(json_data, **kwargs) classmethod

Validate a JSON document as this configuration, reporting invalid options as a component configuration error.

Parameters:

Name Type Description Default
json_data str | bytes | bytearray

The JSON document to validate.

required
**kwargs Any

Keyword arguments passed to BaseModel.model_validate_json.

{}

Returns:

Name Type Description
Self Self

The validated configuration.

Raises:

Type Description
ComponentConfigError

If the document is not valid JSON or an option is invalid.