cleanup and error message for invalid sql output