Note that, in quantum field theory, a generating functional may fail to be invariant under gauge transformations, and gauge symmetries are replaced with the BRST symmetries, depending on ghosts and acting both on fields and ghosts.