We study a contracting model with unforeseen contingencies in which the court is an active player. Ex-ante, the contracting parties cannot include the risky unforeseen contingencies in the contract they draw up. Ex-post the court observes whether an unforeseen contingency occurred, and decides whether to void or uphold the contract. If the contract is voided by the court, the parties can renegotiate a new agreement ex-post. There are two effects of a court that voids more contracts. The parties' incentives to undertake relationship-specific investment are reduced, while the parties enjoy greater insurance againt the unforeseen contingencies which the ex-ante contract cannot take into account. In this context, we are able to characterise fully the optimal decision rule for the court. The behaviour of the optimal court is determined by the trade-off between the need for incentives and the gains from insurance that voiding in some circumstances offers to the agents.