class ValidationError(Exception):
    pass


class LengthValidator(AttributeExtension):

    def __init__(self, max_length):
        self.max_length = max_length

def set(self, state, value, oldvalue, initiator):
    if len(value) > self.max_length:
        raise ValidationError('Length %d exceeds allowed %d' % (len(value),
            self.max_length))
return value
SQLAlchemy — максимальная длина столбца