Unfortunately, any of the protective actions one could take would be legitimately abusive and controlling against someone who ISN'T one of those messed up people. So if someone feels like they need it, either they really shouldn't be getting married to that person (but are in denial), OR they're probably a legit abusive spouse. And really shouldn't be marrying anyone.
And in most places, if you're married, legally you can't stop the partner from entering the 'community' into debt like that, or encumbering community property. So to your point, yeah it couldn't be stopped even with bank tracking. But it is harder to do that way.
The most you could do is make the responsible party take on the debt entirely on their own later when the divorce settles, but anyone likely to do this kind of BS will make that a multi-year living hell. It's rarely worth the attempt, as legal fees will often far outweigh any money recovered.
There is a reason that 99% of family law attorneys will tell men to just not get married. For guys, 99% of them will also tell them to just not let women live with them (due to various ways THAT is often used against men), etc. Pre-nups are important and can reduce the damage, but are not bullet proof.
For women, the system does generally favor them - but they can and will be drug through hell if they end up with a problem spouse too. And can end up with life altering debt (problem gamblers being a common pattern), abusive partners they can't get rid of, etc. They're more likely to be murdered in a bad situation too, by a long shot.
If someone has an actual reasonable spouse (and is actually reasonable) but want to get divorced, then it's actually not that big a deal and it can be resolved relatively quickly. And that does happen. But for the most part, most of those people don't end up needing the system anyway - as both people are actually reasonable.
And people who aren't from backgrounds that result in them being blind to signs of real problem behaviors usually see and avoid the really dangerous people anyway before they can get their hooks in.
The best prevention frankly is having two loving, stable parents who raised someone well, to have not been abused as a child, and to be nurtured, etc.. So that someone knows what 'good' feels like, has reasonable role models that cover the common gender setups and models healthy behaviors, etc. It's far from foolproof though, and those situations are actually quite rare. What is common is setups that LOOK like that, but are actually deeply screwed up when you're inside - but in ways the participants can't or won't see.
Folks with NPD, ASPD, and other Cluster B personalities in particular are powerfully manipulative and destructive, and can pretend to be really amazing and wonderful until you're already 'stuck'. Co-dependent behavior is rampant. Etc.