Abstract: In this paper, we argue that the notion of equity as a safety valve on the law can be seen as part of the law’s response to the problem of opportunism. We define equity as the use of a more flexible, morally judgmental, and subjective mode of legal decision making that roughly corresponds with historical equity. We distinguish opportunists as agents who have unusual willingness and ability to take advantage of necessary imperfections in the law. We present a simple contracting model that captures the role of equity as a safety valve, and show how it can solve problems posed by opportunists. In our model, a simple but imperfect formal legal regime is able to achieve first best in the absence of opportunists. But when opportunists are added, a more flexible regime (equity) – specifically, one that denies damages to parties who exploit contractual gaps – can be preferred. However, equity is also vulnerable to being used opportunistically by the parties it intends to protect. For this reason, we show that it is often preferable to limit equity, reserving it for use only against those who appear sufficiently likely to be opportunists. Our model generates intuitive comparative statics that describe the optimal expansiveness or restrictiveness of equity.