Import the validator
To use the validation features, import thevalidate function from the utils module:
Define a schema
You define your validation rules using a dictionary where each key represents an expected input field. This schema dictates the data types, necessity, and constraints for the incoming data.type(required): Expected input type (e.g.,str,int,float,bool).required(default:False): Whether the field is required.default(default:None): Default value if input is not provided.constraints(optional): A lambda function that returnsTrueorFalseto validate the value.
Validate input in your handler
When implementing validation in your handler, pass the input object and your schema to thevalidate function. The function returns a dictionary containing either an errors key or a validated_input key.
Test the validator
You can test your validation logic locally without deploying. Save your handler code and run it via the command line with the--test_input flag.
test_input.json