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
40 lines (37 loc) · 1.28 KB
/
Copy pathcontracts.py
File metadata and controls
40 lines (37 loc) · 1.28 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
from gateframe.core.contract import ValidationContract
from gateframe.rules.confidence import ConfidenceRule
from gateframe.rules.semantic import SemanticRule
from gateframe.rules.structural import StructuralRule
from .models import RagAnswer
retrieval_contract = ValidationContract(
name="retrieval_check",
rules=[
StructuralRule(schema=RagAnswer),
SemanticRule(
check=lambda output, **ctx: len(output.get("citations", [])) > 0,
name="has_citations",
failure_message="Answer must include at least one citation.",
),
],
)
answer_contract = ValidationContract(
name="answer_quality",
rules=[
StructuralRule(schema=RagAnswer),
SemanticRule(
check=lambda output, **ctx: len(output.get("answer", "")) >= 20,
name="answer_length",
failure_message="Answer is too short to be useful (minimum 20 characters).",
),
ConfidenceRule(
field="confidence",
minimum=0.65,
name="answer_confidence",
),
SemanticRule(
check=lambda output, **ctx: output.get("grounded") is True,
name="grounding_check",
failure_message="Answer must be grounded in retrieved documents.",
),
],
)