Refactor validation (incorrect file names)

This commit is contained in:
Nitwix
2025-04-12 13:38:43 +02:00
parent 7bf0b28188
commit 5558b4c658
8 changed files with 112 additions and 17 deletions

2
.gitignore vendored
View File

@ -273,3 +273,5 @@ devenv.lock
# pre-commit # pre-commit
.pre-commit-config.yaml .pre-commit-config.yaml
.vscode

View File

@ -17,3 +17,4 @@ urllib3==2.4.0
pydantic==2.11.3 pydantic==2.11.3
langchain==0.3.23 langchain==0.3.23
langchain-groq==0.3.2 langchain-groq==0.3.2
email-validator==2.2.0

View File

@ -1,4 +1,9 @@
from validation import FromAccount from datetime import date
from validation.cross_validate import ExtractedData
from validation.from_account import FromAccount
from validation.from_description import FromDescription
from validation.from_passport import FromPassport
from validation.from_profile import FromProfile
account_data = FromAccount( account_data = FromAccount(
@ -15,5 +20,88 @@ account_data = FromAccount(
country="Netherlands", country="Netherlands",
name="Astrid Janneke Willems", name="Astrid Janneke Willems",
phone_number="+31 06 34579996", phone_number="+31 06 34579996",
email="astrid.willems@upcmail.nl" email="astrid.willems@upcmail.nl",
)
description_data = FromDescription(
full_name="Astrid Janneke Willems",
age=28,
nationality="Netherlands",
marital_status="single",
has_children=False,
secondary_education_school="Pieter Nieuwland College Utrecht",
secondary_education_year=2016,
university_name="Webster University Leiden",
university_graduation_year=2020,
occupation_title="Art Dealer",
employer="Rijksmuseum Amsterdam",
start_year=2021,
annual_salary_eur=40000,
total_savings_eur=20000,
has_properties=False,
inheritance_amount_eur=1590000,
inheritance_year=2020,
inheritance_source="grandmother (Oil and Gas Executive)",
)
passport_data = FromPassport(
country="NLD",
passport_number="HW8642009",
surname="WILLEMS",
given_names="ASTRID JANNEKE",
birth_date=date(1997, 1, 19),
citizenship="Austrian/ÖSTERREICH",
sex="F",
issue_date=date(2016, 6, 4),
expiry_date=date(2026, 6, 3),
signature_present=True,
machine_readable_zone="P<NLDWILLEMS<<ASTRID<JANNEKE<<<<<<<<<<<<<<<<<<<HW8642009NLD970119",
)
profile_data = FromProfile(
first_name="Astrid Janneke",
last_name="Willems",
date_of_birth=date(1997, 1, 19),
nationality="Dutch",
country_of_domicile="Netherlands",
gender="Female",
passport_number="HW8642009",
id_type="passport",
id_issue_date=date(2016, 6, 4),
id_expiry_date=date(2026, 6, 3),
phone="+31 06 34579996",
email="astrid.willems@upcmail.nl",
address="Lijnbaan 18, 7523 05 Assen",
politically_exposed_person=False,
marital_status="Single",
highest_education="Tertiary",
education_history="Webster University Leiden (2020)",
employment_status="Employee",
employment_since=2021,
employer="Rijksmuseum Amsterdam",
position="Art Dealer",
annual_salary_eur=40000.0,
total_wealth_range="1.5m-5m",
origin_of_wealth=["Employment", "Inheritance"],
inheritance_details="Grandmother, 2020, Oil and Gas Executive",
business_assets_eur=20000.0,
estimated_annual_income="<250k",
income_country="Netherlands",
commercial_account=False,
investment_risk_profile="High",
mandate_type="Advisory",
investment_experience="Experienced",
investment_horizon="Medium",
preferred_markets=["Denmark", "Netherlands"],
total_aum=1610000.0,
aum_to_transfer=1320200.0,
)
def test_xval_name_account_description() -> None:
data = ExtractedData(
account=account_data,
description=description_data,
passport=passport_data,
profile=profile_data,
) )

View File

@ -2,7 +2,11 @@ from enum import StrEnum
from typing import Any, Callable, Optional from typing import Any, Callable, Optional
from pydantic import BaseModel from pydantic import BaseModel
from validation import FromAccount, FromDescription, FromPassport, FromProfile from validation.from_account import FromAccount
from validation.from_description import FromDescription
from validation.from_passport import FromPassport
from validation.from_profile import FromProfile
class ExtractedData(BaseModel): class ExtractedData(BaseModel):

View File

@ -9,9 +9,9 @@ class FromAccount(BaseModel):
model_config = ConfigDict(validate_assignment=True, str_strip_whitespace=True) model_config = ConfigDict(validate_assignment=True, str_strip_whitespace=True)
# From account.pdf # From account.pdf
account_name: str = Field(..., min_length=1) account_name: str = Field(min_length=1)
account_holder_name: str = Field(..., min_length=1) account_holder_name: str = Field(min_length=1)
account_holder_surname: str = Field(..., min_length=1) account_holder_surname: str = Field(min_length=1)
@model_validator(mode='after') @model_validator(mode='after')
def check_account_name_is_name_surname(self) -> Self: def check_account_name_is_name_surname(self) -> Self:
@ -20,17 +20,17 @@ class FromAccount(BaseModel):
raise ValueError(f'Account name is not name + surname: {self.account_name} != {combined}') raise ValueError(f'Account name is not name + surname: {self.account_name} != {combined}')
return self return self
passport_number: str = Field(..., min_length=5) passport_number: str = Field(min_length=5)
reference_currency: Literal["CHF", "EUR", "USD", "Other"] reference_currency: Literal["CHF", "EUR", "USD", "Other"]
other_currency: Optional[str] = None other_currency: Optional[str] = None
building_number: str = Field(..., min_length=1) building_number: str = Field(min_length=1)
street_name: str = Field(..., min_length=1) street_name: str = Field(min_length=1)
postal_code: str = Field(..., min_length=1) postal_code: str = Field(min_length=1)
city: str = Field(..., min_length=1) city: str = Field(min_length=1)
country: str = Field(..., min_length=1) country: str = Field(min_length=1)
name: str = Field(..., min_length=1) name: str = Field(min_length=1)
phone_number: str = Field(..., min_length=6) phone_number: str = Field(min_length=6)
email: EmailStr email: EmailStr

View File

@ -10,7 +10,7 @@ class FromPassport(BaseModel):
model_config = ConfigDict(validate_assignment=True, str_strip_whitespace=True) model_config = ConfigDict(validate_assignment=True, str_strip_whitespace=True)
country: str = Field(..., min_length=3, max_length=3) # ISO 3166-1 alpha-3 country: str = Field(..., min_length=3, max_length=3) # ISO 3166-1 alpha-3
passport_number: str = Field(..., min_length=9, max_length=9, regex=r"^[A-Z0-9]{9}$") passport_number: str = Field(..., min_length=9, max_length=9, pattern=r"^[A-Z0-9]{9}$")
surname: str = Field(..., min_length=1) surname: str = Field(..., min_length=1)
given_names: str = Field(..., min_length=1) given_names: str = Field(..., min_length=1)

View File

@ -17,7 +17,7 @@ class FromProfile(BaseModel):
gender: Literal["Female", "Male"] gender: Literal["Female", "Male"]
# ID information # ID information
passport_number: str = Field(..., min_length=9, max_length=9, regex=r"^[A-Z0-9]{9}$") passport_number: str = Field(..., min_length=9, max_length=9, pattern=r"^[A-Z0-9]{9}$")
id_type: Literal["passport"] id_type: Literal["passport"]
id_issue_date: date id_issue_date: date
id_expiry_date: date id_expiry_date: date