Guidance and Misguidance: The different kinds of Imams in the Qur'an
The word Imām comes from the Arabic word Amaama which means to come before or stand before like a guide or leader. The primary meaning of the word Imām is guide or leader.
The Quran talks about Imams of guidance and Imāms of misguidance. Verse 28:41 refers to Imams who misguide (Inviting to the fire) and such misguiding Imams exist too.
But the Imams of guidance are mentioned in 2:124 where Abraham and his progeny are appointed by God who says "I make you Imām of mankind". In 21:73 and 32:24 the Quran mentions "Imāms guiding by Our Command". So these are the Imams who guide to God and they are always present in the world even after prophethood ends.
The Infallible Shia Imams are the Imams of guidance and the Quran mentions them in many names and titles like the Ummah of the progeny of Ibrahim and the Middle Ummah who witness over mankind and the Imams who appear on day of judgment in 17:71.