-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcontracts.py
More file actions
73 lines (68 loc) · 2.56 KB
/
contracts.py
File metadata and controls
73 lines (68 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from gateframe.core.contract import ValidationContract
from gateframe.core.escalation import EscalationRoute
from gateframe.core.failure import FailureMode
from gateframe.rules.semantic import SemanticRule
from gateframe.rules.structural import StructuralRule
from .models import ActionPlanOutput, ClassificationOutput, ExecutionOutput, SummaryOutput
classification_contract = ValidationContract(
name="classification",
rules=[
StructuralRule(schema=ClassificationOutput),
SemanticRule(
check=lambda output, **ctx: output.get("confidence", 0) >= 0.5,
name="minimum_confidence",
description="Classification confidence must be at least 0.5",
failure_mode=FailureMode.SOFT_FAIL,
failure_message="Classification confidence below 0.5 threshold.",
),
],
on_hard_fail=EscalationRoute.ABORT,
on_soft_fail=EscalationRoute.FLAG_AND_CONTINUE,
)
action_plan_contract = ValidationContract(
name="action_plan",
rules=[
StructuralRule(schema=ActionPlanOutput),
SemanticRule(
check=lambda output, **ctx: len(output.get("steps", [])) > 0,
name="has_steps",
description="Action plan must have at least one step",
failure_mode=FailureMode.HARD_FAIL,
failure_message="Action plan has no steps.",
),
SemanticRule(
check=lambda output, **ctx: (
output.get("requires_approval", False)
if output.get("estimated_risk") == "high"
else True
),
name="high_risk_needs_approval",
description="High risk actions must require approval",
failure_mode=FailureMode.SOFT_FAIL,
failure_message="High risk plan does not require approval.",
),
],
on_hard_fail=EscalationRoute.HUMAN_REVIEW,
on_soft_fail=EscalationRoute.FLAG_AND_CONTINUE,
)
execution_contract = ValidationContract(
name="execution",
rules=[
StructuralRule(schema=ExecutionOutput),
SemanticRule(
check=lambda output, **ctx: (
output.get("success", False) or len(output.get("details", "")) > 10
),
name="failure_explained",
description="Failed executions must have detailed explanation",
failure_mode=FailureMode.SOFT_FAIL,
failure_message="Execution failed without sufficient explanation.",
),
],
)
summary_contract = ValidationContract(
name="summary",
rules=[
StructuralRule(schema=SummaryOutput),
],
)