Programmatic pages that don't get classified as spam
Programmatic SEO and "scaled content abuse" use the same machinery. The difference Google cares about is whether each page adds information a user could not get more easily elsewhere.
Gate generation on demand and data
The first discipline is restraint: only generate a page where there is both real search demand and real data to populate it. A route page with no inventory, or a comparison with nothing to compare, is thin by construction.
Engineer information gain
Every template should answer "what does this page uniquely know?" If the answer is "nothing the template above it does not", it should not exist as a separate URL.
Done well, programmatic pages are not a loophole. They are the most honest way to serve a long tail of genuine, specific intent at a scale humans cannot write by hand.