the form of the Sacrament of Baptism has two essential elements: the pouring of water over the head of the person to be baptized (or the immersion of the person in water); and the words "I baptize you in the name of the Father, and of the Son, and of the Holy Spirit."
In some Roman communions, if the priest didn't have the right thoughts, then the sacrament was invalid. This, ironically, comes close to that. If x isn't just right, then it is not right. That also brings to mind the old Donatist heresies.
It is my understanding that the Church of Rome recognizes a baptism as valid if:
1. the person to be baptized is dipped into [immersed] in water, or the infant has water poured over their head
2. and the words "I baptize you in the name of the Father, and of the Son, and of the Holy Spirit." are uttered over the baptized person
3. and the baptism is performed with Trinitarian intent. That is to say, the person performing the baptism must intend what the Catholic Church intends in order for the baptism to be valid. Therefore for the baptism to be valid in the eyes of the Church of Rome. when the person performing the baptism baptizes "in the name of the Father, and of the Son, and of the Holy Spirit," he must mean in the name of the Trinity, and he must intend to bring the person being baptized into the fullness of Christ's Church.
On the other hand, if the person performing the baptism is a cultist who denies the Trinity, the Church of Rome would regard the baptism as being invalid.
For instance members of the Church of Jesus Christ of Latter-Day Saints ["Mormons"] refer to themselves as Christians, they do not believe the same thing that Catholics, Canonical Orthodox, and Trinitarian Protestants believe about the Father, the Son, and the Holy Spirit. Rather than believing that these are Three Persons in One God [the Trinity], the LDS cult teaches that the Father, the Son, and the Holy Spirit are three separate deities. Therefore, the Church of Rome
denies the validity of LDS baptism, because Mormons, when they baptize "in the name of the Father, and of the Son, and of the Holy Spirit," do not intend what Christians intend, that is, they do not intend to baptize in the name of the Trinity.
The Church of Rome permits midwives and nurses to perform baptisms of dying infants, and regards these baptisms as valid as long as water is sprinkled or poured on the head of the infant, the words "I baptize you in the name of the Father, and of the Son, and of the Holy Ghost' are used, and the midwife or nurse performs this baptism with Trinitarian intent.