forked from PracticalMind/gateframe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontracts.py
More file actions
53 lines (49 loc) · 1.8 KB
/
contracts.py
File metadata and controls
53 lines (49 loc) · 1.8 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
from gateframe.core.contract import ValidationContract
from gateframe.rules.boundary import AllowedValues, BoundaryRule
from gateframe.rules.confidence import ConfidenceRule
from gateframe.rules.semantic import SemanticRule
from gateframe.rules.structural import StructuralRule
from .models import EscalationCheck, TriageDecision, TriageIntake
intake_contract = ValidationContract(
name="intake",
rules=[
StructuralRule(schema=TriageIntake),
SemanticRule(
check=lambda output, **ctx: 1 <= output.get("severity", 0) <= 10,
name="severity_range",
failure_message="Severity must be between 1 and 10.",
),
],
)
triage_decision_contract = ValidationContract(
name="triage_decision",
rules=[
StructuralRule(schema=TriageDecision),
BoundaryRule(
check=AllowedValues("action", {"treat", "observe", "refer", "discharge"}),
name="action_boundary",
failure_message="Action must be one of: treat, observe, refer, discharge.",
),
BoundaryRule(
check=AllowedValues("priority", {"low", "medium", "high", "critical"}),
name="priority_boundary",
failure_message="Priority must be one of: low, medium, high, critical.",
),
ConfidenceRule(
field="confidence",
minimum=0.6,
name="decision_confidence",
),
],
)
escalation_check_contract = ValidationContract(
name="escalation_check",
rules=[
StructuralRule(schema=EscalationCheck),
BoundaryRule(
check=AllowedValues("assigned_role", {"nurse", "doctor", "specialist", "admin"}),
name="role_boundary",
failure_message="assigned_role must be one of: nurse, doctor, specialist, admin.",
),
],
)