feat: add schema validation for doc input

This commit is contained in:
rsxri 2026-01-06 17:51:02 +00:00
parent 150bb16220
commit 8239c4d57a
4 changed files with 36 additions and 3 deletions

View file

@ -1,8 +1,10 @@
{
"client_name": "Acme Ltd",
"provider_name": "John Doe 2",
"provider_name": "Will Smith",
"payment_type": "hourly",
"hourly_rate_gbp": 40,
"include_confidentiality": false,
"include_ip_clause": false,
"termination_notice_days": 14,
"governing_law": "England and Wales"
}

View file

@ -2,12 +2,17 @@ import json
from pathlib import Path
from jinja2 import Environment, FileSystemLoader
from schema import DocumentInput
def main():
# load input data
# path() over hardcoding str
data = json.loads(Path("examples/input.json").read_text(encoding="utf-8"))
# validate + normalise input
doc_input = DocumentInput(**data)
# setup template eng
# create jinja2 env for templates
env = Environment(
@ -20,7 +25,7 @@ def main():
# load template to render
# **data spreads dict so keys become template vars
template = env.get_template("doc.md.j2")
out = template.render(**data)
out = template.render(**doc_input.model_dump())
# write output - render md to file
Path("out.md").write_text(out, encoding="utf-8")

16
schema.py Normal file
View file

@ -0,0 +1,16 @@
from typing import Literal, Optional
from pydantic import BaseModel, Field
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

View file

@ -25,3 +25,13 @@ laws of england and wales.
{% else %}
{{ governing_law }}.
{% endif %}
## intellectual property
{% if include_ip_clause %}
all intellectual property created during the services remains with the provider.
{% else %}
no intellectual property clause is included.
{% endif %}
## termination
either party may terminate this agreement with {{ termination_notice_days }} days' written notice.