Implement function withSanitizedValue

Comment From: philwebb

Thanks very much @RohanGoyal17!