Validation Logic
Validation Logic
To maintain data integrity within the Supervised AI platform, the testing-api enforces strict validation rules on all incoming and outgoing data. These constraints ensure that AI models receive properly formatted features and that the platform remains resilient against anomalous data distributions.
Input Validation
All API endpoints that accept data for testing or inference require structured payloads. The validation layer checks for data types, mandatory fields, and range constraints before the request reaches the processing logic.
Request Schemas
Requests are validated against the following general criteria:
| Parameter | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| dataset_id | UUID | Yes | The unique identifier for the supervised dataset. |
| payload | Object/Array | Yes | The actual data points to be tested. |
| confidence_threshold | Float | No | Minimum confidence score (0.0 - 1.0) to accept a prediction. |
| metadata | Map | No | Key-value pairs for tracking versioning and environment info. |
Data Integrity Rules
The platform applies specific logic to ensure that AI-specific data (labels, features, and tensors) adheres to the project's requirements.
1. Feature Consistency
The API validates that the input features match the schema defined during the model training phase.
- Dimensionality: Array lengths must match the expected input shape.
- Null Handling: Unless explicitly allowed in the schema,
nullvalues in feature sets will trigger a validation error.
2. Label Mapping
For classification tasks, the input labels must exist within the predefined label set for the specific dataset_id.
// Example of an invalid label submission
{
"prediction": "unknown_class",
"status": "error",
"message": "Label 'unknown_class' is not defined in the supervised project schema."
}
3. Numerical Constraints
To prevent gradient issues and calculation errors, numerical inputs are validated for:
- Range: Values must fall within the specific
[min, max]defined for the feature. - Type: Ensures integers are not passed as floats if the model requires discrete inputs.
Usage Example: Validating a Test Payload
When sending a batch of data for validation, the API returns a structured report if constraints are violated.
curl -X POST https://api.supervised.ai/v1/test/validate \
-H "Content-Type: application/json" \
-d '{
"dataset_id": "8f2b3c4d-...",
"payload": [
{"feature_a": 0.5, "feature_b": 10},
{"feature_a": 1.2, "feature_b": "invalid_type"}
]
}'
Validation Response (Failure):
{
"valid": false,
"errors": [
{
"index": 1,
"field": "feature_b",
"reason": "Expected type 'number', received 'string'."
}
]
}
Handling Validation Failures
The API utilizes standard HTTP status codes to communicate validation results:
400 Bad Request: The request body is malformed (invalid JSON).422 Unprocessable Entity: The JSON is valid, but the data violates business logic or AI integrity rules (e.g., out-of-range values).403 Forbidden: Thedataset_idprovided does not match the authenticated user's permissions.
Developers should catch 422 errors to provide feedback to end-users regarding data quality issues before re-submitting test batches.