Characterizing and predicting the magnetic environment leading to solar eruptions