Philosophical problem of "justified true belief"/Gettier problem. (https://en.wikipedia.org/wiki/Gettier_problem -- I learned about this from one of the Rap Genius founders when I was back in YC, lol.)
Generally the law handles this through the "reasonable man" standard; i.e. "would a reasonable man, knowing what you did at the time, have done what you did?" This would allow you to shoot someone in self-defense who was holding a realistic looking toy gun at a child (which you believed to be a real gun, unlawful intent, etc. at the time).