From bb61418c799d008ba2a2ac0b974f4a4db423d6da Mon Sep 17 00:00:00 2001 From: rsxri Date: Tue, 6 Jan 2026 18:10:55 +0000 Subject: [PATCH] feat: enforce conditional payment validation in schema --- schema.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/schema.py b/schema.py index 04451f5..03c5d18 100644 --- a/schema.py +++ b/schema.py @@ -1,6 +1,6 @@ from typing import Literal, Optional -from pydantic import BaseModel, Field +from pydantic import BaseModel, Field, model_validator class DocumentInput(BaseModel): @@ -13,4 +13,15 @@ class DocumentInput(BaseModel): fixed_fee_gbp: Optional[float] = Field(None, gt=0) include_confidentiality: bool = False - governing_law: str \ No newline at end of file + 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 \ No newline at end of file