Depending on the spacing and timing you can try rolling, or even a ledge jump (hitting jump when you are holding the ledge).
The other option if you can learn the timing is to just simply do a stand from the ledge (pressing towards the ledge while holding). This depends on the character, but I can give data for Marth. This might get technical, so hold on.
Marth's (<100%) stand from ledge has its First Actionable Frame (FAF) on frame 33 and is invincible up until frame 30. What this means is that you are only vulnerable on frames 31 and 32, since you can act on 33.
Marth's Dtilt hits on frames 7-9 and its FAF is on frame 20. What this means is that if you time it perfectly, you can get up, eat his attack, and have 15 frames to act (eat the last frame with frame 30 of your get up. Have 2 frames of non-invincibility and his frame count is at 11. If he keeps spamming and ALSO times it perfectly, you get frames 19-11 + 7 where he cannot act). If his timing is not perfect, you get more frames.
If he chooses to use another move, you have at most 12 frames, since Marth's fastest move is Jab, which hits on frame 4 (again, assuming perfect timing).
In 12 frames, you can do almost any move. I would suggest going for jab, shield or grab. Jab is Marth's fastest move, so if you mess up the timing a little, you still wont be punished. Shield is good because if he is mindlessly dtilting he may hit your shield and then you can shield grab him. Grab is good because even if you mess it up (it comes out on frame 8) you get grab armour during the grab itself, which will allow you to eat his attacks.
Of course, if he is mindlessly spamming, there's a good move that everyone overlooks, and that is counter. Counter is 'active' from frame 5-29, so you can do it out of a roll, ledge drop (dropping down and jumping to the platform) or even from the stand I mentioned earlier. However, the risk with counter is that if you don't get it off, it's a free punish.