RiskAssessment captures the result of evaluating the risk of an action, including a continuous score, a discrete risk level, and an itemized list of contributing factors. RiskFactor describes a single contributing factor to the overall score.
RiskAssessment
Import
Fields
Validation
Thescore field is validated in __post_init__ to ensure it falls within [0.0, 1.0]. Attempting to construct a RiskAssessment with an out-of-range score raises a ValueError.
Python
Score-to-Level Mapping
TheRiskLevel.from_score() classmethod maps continuous scores to discrete levels:
The boundary values are exclusive on the lower end: a score of exactly
0.3 maps to MEDIUM, not LOW. A score of exactly 0.6 maps to HIGH, and 0.8 maps to CRITICAL.Constructing Manually
You can build aRiskAssessment manually for testing or custom integration scenarios.
Trust-Adjusted Assessments
When a trust engine is configured, theCoreAttesta pipeline may produce a RiskAssessment with an additional trust_adjustment factor that shows how the score was modified.
Python
Override Assessments
Whenrisk= is set on the @gate decorator, the scorer is bypassed and a fixed score is used:
The resulting
RiskAssessment has scorer_name="override" and a single manual_override factor.
RiskFactor
Describes a single contributing factor to the overall risk score.Import
Fields
DefaultRiskScorer Factors
The built-inDefaultRiskScorer produces exactly five factors for every assessment:
Example: Iterating Over Factors
The
contribution values are weighted — they represent raw_factor_score * factor_weight. The sum of all contributions equals the overall score (before clamping to [0, 1]). This makes it easy to see exactly how much each factor contributed to the final result.