Autolegal/schema.py

28 lines
920 B
Python
Raw Permalink Normal View History

from typing import Literal, Optional
from pydantic import BaseModel, Field, model_validator
class DocumentInput(BaseModel):
client_name: str = Field(..., min_length=1)
provider_name: str = Field(..., min_length=1)
payment_type: Literal["hourly", "fixed", "other"]
hourly_rate_gbp: Optional[float] = Field(None, gt=0)
fixed_fee_gbp: Optional[float] = Field(None, gt=0)
include_confidentiality: bool = False
governing_law: str
@model_validator(mode="after")
def check_payment_fields(self):
# enforce conditional reqs cleanly
if self.payment_type == "hourly" and self.hourly_rate_gbp is None:
raise ValueError("hourly_rate_gbp is required when payment_type is 'hourly'")
if self.payment_type == "fixed" and self.fixed_fee_gbp is None:
raise ValueError("fixed_fee_gbp is required when payment_type is 'fixed'")
return self