dictutils.ops.schema_check

dictutils.ops.schema_check(d, schema, *, mode='collect')[source]

Validate object against a simple schema.

Parameters:
  • d (Any) – Object to validate

  • schema (Mapping[str, Any]) – Schema definition with nested structure and types

  • mode (str) – “collect” to return errors, “raise” to throw exception

Return type:

list[str]

Returns:

List of validation error messages

Example

>>> import json
>>> data = {"user": {"name": "Alice", "age": "30"}}  # age should be int
>>> schema = {"user": {"name": str, "age": int}}
>>> result = schema_check(data, schema)
>>> print(json.dumps(result, indent=4))
[
    "user.age: expected <class 'int'>, got <class 'str'>"
]