slotmatch / schema.py
GenAIDevTOProd's picture
Upload folder using huggingface_hub
8983b2d verified
raw
history blame contribute delete
908 Bytes
# slotmatch/schema.py
ALLOWED_TYPES = {str, int, float, bool}
class SchemaValidationError(Exception):
"""Custom error when schema is invalid."""
pass
class SchemaValidator:
def __init__(self, schema: dict):
self.schema = schema
self._validate_schema()
def _validate_schema(self):
if not isinstance(self.schema, dict):
raise SchemaValidationError("Schema must be a dictionary.")
for key, expected_type in self.schema.items():
if not isinstance(key, str):
raise SchemaValidationError(f"Key '{key}' must be a string.")
if expected_type not in ALLOWED_TYPES:
raise SchemaValidationError(
f"Unsupported type '{expected_type}' for key '{key}'. "
f"Supported types: {ALLOWED_TYPES}"
)
def get_schema(self):
return self.schema