Earlier quoted context omitted.
That can be contractualized, right?
I believe that's called indentured servitude, and at least in the US, cannot be enforced by contract law.
No, it's not. And, I wouldn't dismiss out of hand what can be "enforced by contract law". The contract itself represents the willingness of two parties to adhere to certain terms. If a company pays you a million dollar signing bonus and asks you for a three year commitment, then you should expect them to demand that bonus back if you leave in two years for reasons not set forth by the terms. And, you should expect claims of "indentured servitude" to fall on deaf ears in court. You can leave. You just can't keep the money.
Similarly, companies wouldn't enforce that the person continue to work for them; simply that they must repay their training costs if they don't.
This is currently done by some companies, for instance, with MBA sponsorships. They're sometimes called "loyalty contracts".