Validation
Validation
Validation
Conduit uses schema information to validate incoming data types and required fields before writing to the database. Validation occurs for:
- POST (insert)
- PUT (full update)
- PATCH (partial update)
Input may be provided in JSON, YAML, TOML, or XML. Conduit normalizes the payload and validates it against the table’s column definitions.
Required Fields
Columns marked as NOT NULL must be present in POST and PUT requests. PATCH requests may omit required fields as long as they are not being set to null.
{
"title": "Dune",
"author": "Frank Herbert"
}
If a required field is missing, Conduit returns a validation error before executing any SQL.
Type Validation
Conduit validates incoming values against the column’s declared type. Examples:
- INTEGER columns must receive numeric values
- REAL columns must receive floating‑point values
- TEXT columns must receive strings
- BOOLEAN columns must receive true/false
If a value cannot be converted to the correct type, Conduit returns a validation error.
Nullability
Columns marked as nullable: false cannot be set to null. PUT requests must include non‑null values for all non‑nullable columns. PATCH requests may omit them but cannot explicitly set them to null.
{
"price": null // invalid if price is NOT NULL
}
Extra Fields
Fields not present in the schema are ignored. This allows clients to send additional metadata without breaking requests.
{
"title": "Neuromancer",
"author": "William Gibson",
"debug": "ignored"
}
Driver-Specific Behavior
Conduit normalizes types based on the configured database driver. For example:
- SQLite treats many types as affinities (INTEGER, TEXT, REAL)
- PostgreSQL enforces strict type matching
- MySQL may coerce numeric strings into numbers
- SQL Server requires explicit type compatibility
Conduit performs validation before SQL execution to ensure consistent behavior across drivers.
Error Responses
Validation errors return a structured response describing the issue.
Errors are localized based on the Accept-Language header.
{
"error": "validation_failed",
"details": "Column 'year' must be an integer"
}
Notes
- Validation occurs before any SQL is executed.
- Schema definitions come directly from the database.
- PUT requires full records; PATCH allows partial updates.
- All input formats (JSON, YAML, TOML, XML) are validated consistently.
- Errors are localized using Conduit’s i18n system.