The following are exempt from criminal liability:
1. Anyone who, at the time of committing the criminal offense, due to any mental anomaly or impairment, is unable to understand the unlawfulness of the act or to act in accordance with that understanding.
A temporary mental disorder will not exempt from punishment when it has been induced by the individual for the purpose of committing the crime or when its commission was foreseen or should have been foreseen.
2. Anyone who, at the time of committing the criminal offense, is in a state of complete intoxication due to the consumption of alcoholic beverages, toxic drugs, narcotics, psychotropic substances, or other substances that produce similar effects, provided that this state was not sought for the purpose of committing the offense or its commission was not foreseen or should have been foreseen, or is under the influence of a withdrawal syndrome due to dependence on such substances, which prevents them from understanding the unlawfulness of the act or acting in accordance with that understanding.
3. Anyone who, due to perceptual disturbances from birth or childhood, has a severely impaired awareness of reality.
4. Anyone acting in defense of their own person or rights, or those of others, provided the following requirements are met:
First. Unlawful aggression. In the case of defense of property, an attack on said property that constitutes a crime and places it in serious danger of imminent damage or loss shall be considered unlawful aggression. In the case of defense of a dwelling or its outbuildings, unlawful entry into said dwelling or outbuildings shall be considered unlawful aggression.
Second. Rational necessity of the means employed to prevent or repel the aggression.
Third. Lack of sufficient provocation on the part of the defender.
5. Anyone who, in a state of necessity, in order to avoid harm to themselves or others, injures a legally protected right of another person or breaches a duty, provided the following requirements are met:
First. That the harm caused is not greater than the harm sought to be avoided.
Second. That the state of necessity was not intentionally provoked by the individual.
Third. That the person in need is not obligated to make the sacrifice by virtue of their profession or position.
6. Anyone acting under the influence of overwhelming fear.
7. Anyone acting in the performance of a duty or in the legitimate exercise of a right, profession, or position.
In the cases of the first three points, the security measures provided for in this Code shall apply, where appropriate.