Split a batch of ingested records into valid rows and rejects. A record is valid when every required field is present, non-null, and of the declared type.
Input schema
solve(records: list[dict], schema: dict[str, str]) -> tuple[list[dict], list[dict]]
schema values are one of: "int" | "float" | "str" | "bool"
Example
records = [{"id": 1, "name": "a"}, {"id": "x", "name": "b"}, {"id": 3}]
schema = {"id": "int", "name": "str"}
Output
valid = [{"id": 1, "name": "a"}]
rejects = [{"record": {"id": "x", "name": "b"}, "field": "id", "reason": "type"},
{"record": {"id": 3}, "field": "name", "reason": "missing"}]
Constraints
- Report the first failing field in schema order, not all of them
bool is not an acceptable int- Input order is preserved in both lists
- Up to 500,000 records
Community-reported interview topic. Not an official company question and no affiliation is implied.