from rest_framework.validators import ValidationError def validate_text(config, string): string = str(string) # might cause error with number ? try: validators = config["validators"] for validator in validators: validator_content = validators[validator] if validator == "max_length": if len(string) > validator_content: raise ValidationError("Your text is too long !") else: raise Exception("Dev, you have implement something here...") except KeyError: pass