-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
63 lines (48 loc) · 1.7 KB
/
models.py
File metadata and controls
63 lines (48 loc) · 1.7 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
"""
Pydantic models for strict request/response validation.
All enums are exhaustive - invalid values will fail fast.
"""
from pydantic import BaseModel, Field, field_validator
from typing import Literal, Optional
from enum import Enum
class UserPlan(str, Enum):
FREE = "free"
PRO = "pro"
ENTERPRISE = "enterprise"
class Channel(str, Enum):
EMAIL = "email"
CHAT = "chat"
REVIEW = "review"
SOCIAL = "social"
class Decision(str, Enum):
IGNORE = "ignore"
STANDARD_RESPONSE = "standard_response"
PRIORITY_RESPONSE = "priority_response"
IMMEDIATE_ESCALATION = "immediate_escalation"
class Priority(str, Enum):
LOW = "low"
MEDIUM = "medium"
HIGH = "high"
CRITICAL = "critical"
class DecisionRequest(BaseModel):
"""Incoming customer message with context."""
message: str = Field(..., min_length=1, max_length=5000)
user_plan: Optional[UserPlan] = UserPlan.FREE
channel: Optional[Channel] = Channel.EMAIL
history: Optional[list[str]] = Field(default_factory=list, max_length=50)
@field_validator('message')
@classmethod
def validate_message(cls, v: str) -> str:
"""Ensure message isn't just whitespace."""
if not v.strip():
raise ValueError("Message cannot be empty or whitespace only")
return v.strip()
class DecisionResponse(BaseModel):
"""Strict output schema - no deviation allowed."""
decision: Decision
priority: Priority
churn_risk: float = Field(..., ge=0.0, le=1.0)
confidence: float = Field(..., ge=0.0, le=1.0)
recommended_action: str = Field(..., min_length=1, max_length=500)
class Config:
use_enum_values = True # Return string values, not enum objects