Serotonin is implicated in mood and affective disorders 1,2 but growing evidence suggests that its core endogenous role may be to promote flexible adaptation to changes in the causal structure of the environment 3-8 . This stems from two functions of endogenous serotonin activation: inhibiting learned responses that are not currently adaptive 9,10 and driving plasticity to reconfigure them 11-13 . These mirror dual functions of dopamine in invigorating reward-related responses 14,15 and promoting plasticity that reinforces new ones 16,17 . However, while dopamine neurons are known to be activated by reward prediction errors 18,19 , consistent with theories of reinforcement learning 18,20 , the reported firing patterns of serotonin neurons 21-23 do not accord with any existing theories 1,24,25 . Here, we used long-term photometric recordings in mice to study a genetically-defined population of dorsal raphe serotonin neurons whose activity we could link to normal reversal learning. We found that these neurons are activated by both positive and negative prediction errors, thus reporting the kind of surprise signal proposed to promote learning in conditions of uncertainty 26,27 . Furthermore, by comparing cue responses of serotonin and dopamine neurons we found differences in learning rates that could explain the importance of serotonin in inhibiting perseverative responding. Together, these findings show how the firing patterns of serotonin neurons support a role in cognitive flexibility and suggest a revised model of dopamine-serotonin opponency with potential clinical implications.