Skip to main content
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

The score 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

The RiskLevel.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 a RiskAssessment manually for testing or custom integration scenarios.

Trust-Adjusted Assessments

When a trust engine is configured, the CoreAttesta pipeline may produce a RiskAssessment with an additional trust_adjustment factor that shows how the score was modified.
Python
Trust adjustment never downgrades CRITICAL-level actions. If the original assessment is CRITICAL (score >= 0.8), the trust engine is bypassed entirely and the original score is preserved. This is a safety invariant.

Override Assessments

When risk= 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-in DefaultRiskScorer produces exactly five factors for every assessment:

Example: Iterating Over Factors

Sample output for a destructive action in production:
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.