How do we ensure that a model generalize well in the real world
You should try out the model that you built in real world by using test data that reflect real data.

Machine learning is an iterative process, you have to try it out and see the performance. 


Your test data should be extended to reflect real life scenario that you expect it to work well. 
You might want to change your objective function sometimes, your existing objective function might not have capture some real life factor. For example, if you see your model keep making mistakes on certain type of data, you might want to penalize it more. 
Your model might not last forever, real life data might change over time and you have to tune your model to adapt to it. Your model might not have forseen some scenarios and might not know what should be the correct response to be.