detailed_validate()
Validate data against a schema with detailed error reporting.
Usage
detailed_validate(
schema,
data,
strict=True,
)Performs comprehensive validation of data against the provided schema dictionary. Each key in the schema maps to a type or validator specification.
Parameters
schema: dict-
Validation schema. Keys are field names, values are type objects or callable validators. Example:
schema = { "name": str, "age": int, "email": lambda x: "@" in x, } data: dict-
Data dictionary to validate.
strict: bool = True-
If True (default), raise on first error. If False, collect all errors and return them.
Returns
dict-
Validation report with keys:
"valid"(bool) — overall result"errors"(list) — list of error messages"fields_checked"(int) — count of fields validated
Raises
ValueError-
If
strict=Trueand validation fails. KeyError-
If schema references a field not present in data.
Notes
Schema validators receive the value and should return True for valid data or raise an exception/return False for invalid.
Examples
>>> detailed_validate({"name": str}, {"name": "Alice"})
{'valid': True, 'errors': [], 'fields_checked': 1}