How does the car know the EGR valve is bad?

If the egr valve was stuck open, the engine wouldn't idle. If the egr valve was stuck closed you may hear excessive pinging (spark knock) and in most vehicles, the check engine light would illuminate.