Schema & Validation¶
A schema file describes the expected shape and types of your configuration. When you provide a schema, EzConfy:
- Validates every config value against the declared type
- Returns a Pydantic
BaseModelinstance with dot access
YAML Structure¶
A schema can have two top-level keys:
Shorthand syntax
If you don't need custom types, the entire file is treated as the root schema — no types/schema wrapper needed:
If you define types, you must also define schema.
Primitive Types¶
These map directly to Python's float, int, str, and bool.
Optional Types¶
Append ? to make a field optional. It defaults to None if not present in the config:
Default Values¶
Use = value to set a default:
If the config file omits these fields, the defaults are used.
Lists¶
Warning
The element type is validated too — hidden_dims: [256, "oops"] would fail validation.
Union Types¶
Use | to accept multiple types:
Nested Objects¶
Indent to create a nested structure:
This creates nested Pydantic models. Access them with cfg.training.lr.
Custom Types¶
Define reusable types in the types section.
Enums¶
A list of values creates an enum:
Nested model types¶
A dictionary creates a reusable model:
types:
DataConfig:
root: str
num_workers: int = 4
schema:
train_data: DataConfig
test_data: DataConfig
Inheritance¶
Use < to inherit from another type:
types:
BaseModel:
name: str
hidden_dim: int
LargeModel < BaseModel:
num_layers: int
dropout: float
schema:
model: LargeModel
LargeModel inherits all fields from BaseModel and adds its own.
External Types¶
Import any Python class using module:ClassName syntax:
Info
External types are validated with isinstance — EzConfy checks that the instantiated object is actually an instance of the declared type.