Feature Range Validation
Feature Range Validation
Before passing data through a trained model, a production pipeline must validate that inputs conform to the expected schema. Out-of-range values indicate upstream bugs, sensor failures, or unexpected data sources.
You are given:
X: a 2D feature matrix of shape (n, d)schema: a list of d dicts, each with keys "min" and "max" for that columnReturn a list of violation dicts, one per out-of-range value, with keys:
"row": row index (int)"col": column index (int)"value": the actual value (float)Return violations in row-major order (row 0 before row 1; within a row, lower col index first). Return an empty list if all values are in range.
Example:
X = [[1, 200], [3, 4]] schema = [{"min":0,"max":5}, {"min":0,"max":100}]
→ [{"row": 0, "col": 1, "value": 200.0}] ← 200 > 100Your task:
Implement validate_ranges(X, schema) returning a list of violation dicts.
Example Tests
One value above max: single violation returned
Input: {"X":[[1,200],[3,4]],"schema":[{"max":5,"min":0},{"max":100,"min":0}]}
Expected: [{"col":1,"row":0,"value":200}]
All values in range: empty violation list
Input: {"X":[[0.5,0.5],[0.1,0.9]],"schema":[{"max":1,"min":0},{"max":1,"min":0}]}
Expected: []
Value exactly at boundary is valid (inclusive bounds)
Input: {"X":[[0,1]],"schema":[{"max":1,"min":0},{"max":1,"min":0}]}
Expected: []