In practice, enforcing such a contract is extremely difficult, so companies don't spend much effort to collect from someone they know doesn't have the money. Usually what happens is, if you leave before the contract terms are met, they will withhold your final paycheck, citing the contract, and dare you to try and collect it.