Leverage WP_Rewrite to pre-validate links / detect invalid links

You could call get_post_type with the id to check its type before outputting the permalink.