one can pray behind any muslim even if they have some wrong understanding provided that they have not forsake their religion means they do not reject any of the essentials of deen which are known by necessity for example the akaid which are established in quran sunnah and agreed upon by the ummah so anyone who considers quran to be incomplete for example god forbid or anyone who considered rasulullah not to be the final prophet or prophet but there was someone after him or there is it was supposed to be someone else as a prophet but it was given to him accidentally by jibril the will did betray and the funny ideas like that among muslims there are certain groups of people who claim uh and then they believe in those things sometimes they hide it sometimes they declare it so it is very difficult to identify who is who provided you get this clear you shouldn’t be praying behind such people obviously if they are they do not hold any of those faulty understanding they do not go against the critical essentials of islam then you can pray behind them whether they are sunnis or shias provided they have that clarity and if you do not know then stay on the safe side you don’t have to pray behind everyone and everyone although even if it’s valid so you can just be reassured if you’re stuck just pray and then repeat it maybe afterwards so those are all the possibilities make it easy