add schema validation and proper error reporting