There are a number of apps to handle this. Basically when you get a call they validate the phone number against a DB of bad numbers, checks if it’s a “neighbor scam” (your number is 212-501-9901, so it scams 212-501-8404), and then checks if the number is in your contacts before it lets it through. If it thinks it’s spam, it can either label it as such on your incoming call screen or block the call entirely.
Long story short, Nomorobo is the best but they charge and Hiya works just OK (about 80% accuracy, in my experience) but is free. Since Hiya checks against your contacts it is unlikely to have false positives, I’ve never missed a call I wanted.