Generalized rule application promotes flexible behavior by allowing individuals to adjust quickly to environmental changes through generalization of previous learning. Here, we show that bluestreak 'cleaner' wrasse (Labroides dimidiatus) uses generalized rule application in their use of predators as social tools against punishing reef fish clients. Punishment occurs as cleaners do not only remove ectoparasites from clients, but prefer to feed on client mucus (constituting cheating). We tested for generalized rule application in a series of experiments, starting by training cleaners to approach one of two fish models in order to evade punishment (by chasing) from a 'cheated' client model. Cleaners learned this task only if the safe haven was a predator model. During consecutive exposure to pairs of novel species, including exotic models, cleaners demonstrated generalization of the 'predators-are-safe-havens' rule by rapidly satisfying learning criteria. However, cleaners were not able to generalize to a 'one-of-two-stimuli-presents-a-safe-haven' rule, as they failed to solve the task when confronted with either two harmless fish models or two predator models. Our results emphasize the importance of ecologically relevant experiments to uncover complex cognitive processes in non-human animals, like generalized rule learning in the context of social tool use in a fish.