broadly Jupiter is sheltering Earth from asteroids, to such great extent that it may be a prerequisite to life that habitable water planets share the system with a gas giant. Certainly you’re right that this solution is not perfect.
Bit of a nitpick - Jupiter tends to shield the inner solar system from comets that originate far out, but not necessarily asteroids. For bodies in the asteroid belt, there's some thought that Jupiter perturbs as many to a perihelion near Earth's orbit as it diverts away. And without Jupiter, the asteroid belt itself would have accreted into a terrestrial planet instead of remaining loose. Jupiter's overall effect on shielding Earth is uncertain.