# CSV schema check

`csv-schema-check` · version 1.0.0 · CSV & tables · free, no key needed

Validate a CSV document against an ordered column list and per-column string constraints.

**Use when you need to: csv schema check · validate csv columns · check csv column constraints.**

## Supported

- csv schema check
- validate csv columns
- check csv column constraints

## Not supported

- infer types
- coerce values
- locale number formats
- regex cell patterns
- json schema
- read files
- fetch urls

## Behavior

- The first CSV record is the header row; parse failures throw.
- columns.name list must equal the CSV headers in order; a mismatch reports one header_mismatch at row 0 and does not check data rows.
- any accepts every cell including empty; nonempty requires cell length greater than 0.
- integer accepts canonical integer strings including -0, with at most 1000 digits excluding sign; empty fails.
- decimal is a string grammar check: optional ASCII minus, digits, optional single dot with a digit on at least one side, no exponent, at most 1000 characters; empty fails.
- No trimming, case folding, type coercion, or locale-dependent number parsing is performed.
- Up to 100 violations are collected then checking stops; truncated is true when more violations exist.

## Input

- `csv` (string, required): max length 256000
- `columns` (array of object, required): max items 256

## Output

- `valid` (boolean, required)
- `rows_checked` (integer, required)
- `truncated` (boolean, required)
- `violations` (array of object, required): max items 100

## Limits

- max input bytes: 256000
- max data rows: 5000
- max columns: 256
- max header name bytes: 256
- max violations: 100
- max integer digits: 1000
- max decimal characters: 1000

## Example

Request input:

```json
{
  "csv": "id,name,amount,note\n1,Ada,1.5,\n-0,Lin,5.,ok\n",
  "columns": [
    {
      "name": "id",
      "constraint": "integer"
    },
    {
      "name": "name",
      "constraint": "nonempty"
    },
    {
      "name": "amount",
      "constraint": "decimal"
    },
    {
      "name": "note",
      "constraint": "any"
    }
  ]
}
```

Response:

```json
{
  "result": {
    "valid": true,
    "rows_checked": 2,
    "violations": [],
    "truncated": false
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "csv-schema-check",
  "version": "1.0.0",
  "input": {
    "csv": "id,name,amount,note\n1,Ada,1.5,\n-0,Lin,5.,ok\n",
    "columns": [
      {
        "name": "id",
        "constraint": "integer"
      },
      {
        "name": "name",
        "constraint": "nonempty"
      },
      {
        "name": "amount",
        "constraint": "decimal"
      },
      {
        "name": "note",
        "constraint": "any"
      }
    ]
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/csv-schema-check/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"csv":"id,name,amount,note\n1,Ada,1.5,\n-0,Lin,5.,ok\n","columns":[{"name":"id","constraint":"integer"},{"name":"name","constraint":"nonempty"},{"name":"amount","constraint":"decimal"},{"name":"note","constraint":"any"}]}'
```

The machine-readable contract is at [/v1/tools/csv-schema-check/versions/1.0.0](/v1/tools/csv-schema-check/versions/1.0.0).

### CLI

```sh
node cli.mjs run csv-schema-check 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [CSV split column](/tools/csv-split-column): Split one CSV column on an exact separator into uniquely named columns.
- [CSV abs integer column](/tools/csv-abs-integer-column): Replace every data cell in a named CSV column with the absolute value of a canonical integer.
- [CSV clamp integer column](/tools/csv-clamp-integer-column): Clamp every data cell in a named CSV column to optional canonical integer min and max bounds.
- [CSV dedupe](/tools/csv-dedupe): Remove duplicate CSV data rows while preserving the first occurrence.
- [CSV distinct values](/tools/csv-distinct-values): List distinct exact values of one CSV column in first-seen order.
- [CSV drop columns](/tools/csv-drop-columns): Drop named CSV columns and keep the remaining columns in original header order.
