Learning to do the right thing