One way of making them stay is to have a prestigious sprint stage near the end of the tour like the Champs Élysées.
Brutal back to back mountain stages in horrible weather where they might fail to make the time cut and a TT probably doesn’t sound that appealing to a sprinter.
It's not just sprinters either. In his GCN doco, Boardman said he had an agreement to only stay for 10 stages of the TDF so he could go for the win in the prologue and then bugger off to concentrate on the Worlds or something.
I think it is a bit shit everyone leaving early, especially if you do it while gushing about what a great race it is.
It devalues the maglia ciclamino as well if it's awarded to the only sprinter who hasn't fucked off early rather than the most consistent.