-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.py
More file actions
22 lines (18 loc) · 955 Bytes
/
Copy pathvalidate.py
File metadata and controls
22 lines (18 loc) · 955 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Step 4 — Task 4: Pydantic Validation (batch)
# validate_records() runs every record through WeatherReading and splits the
# results into a valid list and an error list. pipeline.py calls this once for
# all records combined, then stores the valid ones and saves the errors to JSON.
from pydantic import ValidationError
from models import WeatherReading
def validate_records(
records: list[dict], source: str
) -> tuple[list[WeatherReading], list[dict]]:
"""Validate records against WeatherReading and return (valid_list, error_list).
Each error dict must contain:
index - position of the record in the input list
source - the source string passed in (e.g. "api" or "csv")
raw_record - the original dict
error_details - the Pydantic error list (ValidationError.errors())
"""
# TODO: iterate over records, try WeatherReading(**record), accumulate results
raise NotImplementedError