Importance of prayer?

I saw this in a sheet by the Fathers of Mercy:

If you have prayed at the time of temptation (i.e., precisely to help dispel the
temptation), you can be sure you did not commit a mortal sin.

This is pretty encouraging, but I was just wondering, is this absolutely true? We will never be in mortal sin if we just pray as soon as we see that we might sin?

Something similar to this, I found a quote by St Alphonsus against sins against purity:

It is well known-----and our Lady’s clients experience the fact every day-----that her great name gives that special strength which is needed to conquer temptations of the flesh. So St. Peter Chrysologus says that the name of Mary is an indication of chastity.

He meant that if some are worried whether they consented to impure thoughts, but remember that they invoked Mary’s name, they have a certain proof that they did not sin.

Prayer is the breathing of the soul.

Christi pax.

I am neither an academic or a philosopher, but I think prayer “works” if we submit to it and not to the temptation. We are called to holiness and we should want holiness. I don’t think that a “holy” thought neutralizes a sin, but it can help us avoid the temptation.

DISCLAIMER: The views and opinions expressed in these forums do not necessarily reflect those of Catholic Answers. For official apologetics resources please visit www.catholic.com.