Serotonin is a clinically important neuromodulator that has been implicated in the regulation of many behavioural and physiological functions, but which has eluded a coherent conceptualization. Computational theories of serotonin function have emphasized its role in affective behaviour, particularly in responses to negative reinforcement and in conditions in which patience is required. Here I will present results from recent studies using optogenetic approaches in mice that have allowed us to selectively record and stimulate serotonin neurons with high selectivity and temporal precision. We find that serotonin neurons are phasically activated by prediction errors, signalling both positive and negative surprises. We also find that such serotonin transients produce rapid modulation of behaviour that is context-dependent and is neither positively or negatively reinforcing. Furthermore, at the neuronal level, we find that serotonin precisely regulates the balance between spontaneous and sensory-driven activity. Based on these and other data, we suggest a view in which the primary role of serotonin in neural computation is the report of uncertainty and its use for the regulation of internal models that drive adaptive behaviour.