# pipeline/validation.py from typing import Literal, Optional from pydantic import BaseModel, Field, field_validator class DocMetadata(BaseModel): methodology_type: Literal["experimental", "observational", "review", "simulation", "mixed"] dataset_source: str = Field(min_length=3) year: int = Field(ge=1950, le=2030) primary_metric: Optional[str] = None confidence_score: Optional[float] = Field(default=None, ge=0.0, le=1.0) @field_validator("dataset_source") @classmethod def strip_whitespace(cls, v: str) -> str: return v.strip() @field_validator("methodology_type", mode="before") @classmethod def normalize_methodology(cls, v: str) -> str: # Qwen occasionally returns "Experimental" despite instructions return v.lower().strip() if isinstance(v, str) else v