Add middleware validation function