Edward Glaeser writes,

there are cases where freedom to contract is and should be imperfect. For example, many contracts rely on expensive government enforcement, and it is reasonable to set limits on the scope of government action in this, as in every, setting. An employment contract with a lifetime non-compete clause, for example, relies on governmental agents enforcing a prohibition against a worker for decades.

It is also costly for the government to enforce intellectual property protection, particularly overseas. Does that mean that the scope of government in this area ought to be limited?

In practice, something like a non-compete agreement is going to be enforced primarily by the firm that wrote the agreement. The only thing that government has to do is provide a court to resolve any disputes. (Maybe the same is true for intellectual property.)

Even if a contract imposes large burdens on the court system, it is not clear that this is inefficient. One can imagine the contracting parties paying for court costs, in which case it is no imposition on the rest of us.