Rules per column, across columns and against a second file

CSV Schema Validator

Describe what each column must look like (type, required, pattern, allowed values, range, length, unique, date format), add comparisons between columns and a foreign key into a second CSV, or import a Frictionless Table Schema, then get a row-by-row error report and flagged or cleaned files.

Data

Drop the CSV or XLSX to check

Up to 25 MB and 300,000 rows

Second CSV for foreign keys (optional)

Its columns become the lookup targets

Load a CSV (or choose Load example) to start writing rules.

CSV Schema Validator

Operator: Abdulla Al Fahad. How tools are built and checked

A spreadsheet that looks fine can still break an import: a date that does not exist, a customer id that is missing from the customer file, an order shipped before it was placed. This page checks each cell against rules you write and lists every failure with its row number and reason. The bad rows can then go back to whoever sent them, each with its reason.

Rules can be set per column (type, required, unique, pattern, allowed values, minimum, maximum, length, date format), between columns (A on or before B), against a second CSV (a foreign key), or imported from a Frictionless Table Schema. Good and bad rows then download as separate files, or as one file with a status and an error column.

Key features

  • Ten column types: any text, text, whole number, number, true or false, date, datetime, email, URL and UUID
  • Required, unique, whole-value regex pattern, allowed list, minimum, maximum, minimum length and maximum length per column
  • Column comparisons (less than, at most, greater than, at least, equal, different) that compare numbers and dates as values
  • Foreign keys against a second CSV or the same file, and composite primary keys from a Table Schema
  • Frictionless Table Schema import and export, and a Suggest rules button that fills rules in from the data
  • Downloads of the flagged CSV, valid rows only, invalid rows only and the errors list

Which rules can be set and how each is checked

A whole number takes an optional sign and digits; a number adds decimals and exponents; true or false accepts true, True, TRUE, 1 and false, False, FALSE, 0, as Frictionless does, unless you list your own true and false words (yes and no, say) for that column. A date accepts YYYY-MM-DD, DD/MM/YYYY, MM/DD/YYYY or YYYY/MM/DD, whichever you choose, and the calendar is checked, so 29 February needs a leap year. A datetime is ISO 8601 with an optional offset, and email, URL (http or https) and UUID use fixed patterns.

A pattern must match the whole value, so C-\d+ accepts C-17 and rejects XC-17. Allowed values are one per line and compared exactly, so an entry such as Smith, J keeps its comma. Minimum and maximum apply to number, whole number, date and datetime columns, with a date bound read in the column's own format first and ISO second, and length counts characters. A rule for a column the file does not have is skipped with a notice.

Missing values are matched exactly, as the Frictionless standard does: an empty cell counts as missing while the Empty cells box is ticked, and a marker such as NULL matches only NULL, not null. A required column reports an error for a missing cell and every other rule is skipped for it, which is also how foreign keys and comparisons treat blanks. Duplicate checks compare trimmed values and name the row of the first occurrence.

How it works

Rows are checked in slices of 5,000, so the page stays responsive and Cancel works. Errors are counted by rule and by column across the whole file, but only the first 5,000 are kept for the table and the errors CSV. The flagged, valid-only and invalid-only files mark every row, with messages kept for the first 50,000 invalid rows.

When to run it

  • An operations clerk receives a supplier's price list each week. The rules say sku matches [A-Z]{3}-\d{4}, price is a number of at least 0 and valid_to is on or after valid_from, and rows that fail go back to the supplier as the invalid-only file with the reasons in the _errors column.
  • A data engineer imports the team's Frictionless schema from the repository so the checks match the load job; its primaryKey of order_id and line_no makes both columns required and checks the pair for duplicates.
  • A product owner loads the customer file as the second CSV and checks that every customer_id in an order export exists in it. Unknown ids are listed with their row numbers.
  • A finance analyst sets closing_date to be on or after opening_date, then sends the valid-only CSV to the ledger import.

Running a check

  1. Load the CSV or XLSX, or paste CSV, and add a second CSV if you need a foreign key.
  2. Pick a column and set its rules, or press Suggest rules from the data and edit the result.
  3. Add comparisons and foreign keys, or import a Table Schema JSON.
  4. Press Validate. Cancel stops a long run.
  5. Filter the report by rule, then download the flagged, valid-only, invalid-only or errors file.

Example

Five order rows checked against eight column rules, ordered_on <= shipped_on, and customer_id in customers.csv

order_id,customer_id,email,status,quantity,unit_price,ordered_on,shipped_on
1001,C-17,ana@example.com,paid,2,19.90,2024-03-01,2024-03-03
1002,C-18,ben@example,paid,1,5.00,2024-03-02,2024-03-01
1003,C-99,chi@example.com,shipped,0,12.50,2024-03-05,2024-03-06
1003,C-17,dev@example.com,refunded,3,abc,2024-13-01,
1005,,eli@example.com,paid,4,7.25,2024-03-09,2024-03-12

Error report

Row 2  email  type: "ben@example" is not an email address
Row 2  ordered_on  compare: ordered_on (2024-03-02) must be at most shipped_on (2024-03-01)
Row 3  quantity  min: 0 is below the minimum 1
Row 3  customer_id  foreign key: "C-99" is not in customers.csv.customer_id
Row 4  order_id  unique: duplicates row 3
Row 4  unit_price  type: "abc" is not a number
Row 4  ordered_on  type: "2024-13-01" is not a valid date in YYYY-MM-DD form
Row 5  customer_id  required: a value is required

Limits

Frictionless export leaves out what the standard cannot hold: column comparisons, foreign keys into a second file and the date orders beyond the four offered. The rules on this page can be stricter than the file you export.

Suggested rules describe the file you loaded, so one bad value in a supposedly clean file turns a number column into text. Check the suggestion for the columns that matter.

Number fields from a Table Schema that set groupChar, decimalChar or bareNumber are not interpreted: values such as 1,234.50 or $12 are reported as not numbers, and an import notice names each field so the failures are not a surprise.

The valid-only file is meant for loading into another system, so it keeps phone-style values such as +44 20 7946 0000 exactly as they are, and a plain number such as -250.00 is never prefixed in any download. Every other value that starts with = + - or @ still gets a leading apostrophe, and the flagged and invalid-only files, which people read in a spreadsheet, prefix phone-style values too.

Patterns you type run on every row in your browser. A pattern with nested quantifiers such as (a+)+ can take very long on a long non-matching value. Cancel works between slices of 5,000 rows but cannot interrupt one stuck match, so keep patterns simple.

  • Press Suggest rules from the data on a known-good file first. It writes types, ranges and code lists from that file for you to tighten by hand, and Export current rules saves them as a Table Schema for the next file.

Common errors and how to fix them

"The pattern for email is not a valid regular expression."
The pattern failed to compile, often from an unclosed bracket or group. Patterns use JavaScript regular expression syntax and are matched against the whole value, so no ^ or $ is needed.
"The foreign key target column ... is not in customers.csv."
The target column was chosen for a different second file, or the file was replaced. Pick the target again after loading the second CSV; changing between the second file and this file clears the target.
"The comparison ... names a column the file does not have."
Rules are kept by column name when you load another file. Remove the comparison, or reload the file whose headers it was written for.

Best practices

  • Validate before you transform. Send the invalid-only file back first, so a later cleaning step cannot hide the cause of an error.
  • Keep the exported schema JSON beside the data contract in version control and treat a changed rule as a change to the contract.

Row numbers and the downloaded files

Row 1 is the first row under the header, whatever line it sits on in the file, so a quoted multi-line cell does not shift the numbers. The flagged file adds _status (ok or invalid) and _errors (up to five messages joined with a vertical bar), and the valid-only file keeps the original columns.

A value that begins with = + - or @ can be run as a formula when a spreadsheet opens the file, so every download puts an apostrophe in front of each one, except a plain number such as -250.00 or +15. The valid-only file, which is meant for import, also skips it for a plus sign followed by digits, spaces, hyphens and brackets (seven digits at least), so +44 20 7946 0000 survives, while -1+2 and =SUM(A1) are still prefixed.

What is mapped from a Table Schema

String, integer, number, boolean (with trueValues and falseValues), date, datetime and year fields are mapped, with the email, uri and uuid formats for strings; the constraints required, unique, pattern, enum, minimum, maximum, minLength and maxLength; primaryKey, single or composite, where every key field becomes required; single-field foreignKeys, where a resource of the empty string means the same file; and missingValues, taken exactly as listed.

Other types (time, duration, geopoint, object, array) are named in a notice as not checked, and only their constraints apply.

Frequently asked questions

How is this different from Validate CSV here?

Validate CSV checks structure: row widths, unclosed quotes, empty or duplicate headers. This page assumes the structure is sound and checks what each cell holds against rules you define, so run the structure check first when a file might be malformed.