As long as you are unaware that you are carrying Najasah (impurity), your Prayer is valid.
Evidence for doubt (uncertainty) and certainty is in the Hadith of Al-Bukhari (2056):
The Prophet (ﷺ) was asked: 'If a person feels something during his prayer, should one interrupt his prayer?' The Prophet (ﷺ) said: "No, you should not give it up unless you hear a sound or smell something!"
And therefore Shaykh Uthaymin (rh) said:
'This Hadith, in which the Messenger of Allah (ﷺ) issued a ruling, is regarded as an important Shari'ah principle, which is that certainty cannot be dispelled by doubt, and matters remain as they are. So long as [your] Taharah (purity) is certain, then it cannot be changed by mere doubt. So long as the state of purity remains valid, then it is to be regarded as valid until it is proven that it has been invalidated. This Hadith offers ease and reassurance to the individual, as it keeps him far away from waswas and doubts, because by means of this narration, doubt is dispelled and what he is certain about remains, namely [his] Taharah.' Fatawa Nur a'la ad-Darb (56/119)
Now about the specific narration regarding your main issue:
While the Messenger of Allah (ﷺ) was leading his Companions in prayer, he took off his sandals and laid them on his left side; so when the people saw this, they removed their sandals. When the Messenger of Allah (ﷺ) finished his prayer, he asked: "What made you remove your sandals?" They replied: 'We saw you remove your sandals, so we removed our sandals.' The Messenger of Allah (ﷺ) then said: "Jibril came to me and informed me that there was filth in them. When any of you comes to the Mosque, he should see; if he finds filth on his sandals, he should wipe it off and pray in them." Narrated in Abu Dawud (650) and Shaykh Albani graded it Sahih
Here you see that the Prophet (ﷺ) did not know about his condition, and when he was informed, then he removed it while continuing to finish his prayer.
When you did not notice that urine or something similar is on you, then it is as you have it not on you.