# validation

> Validate writes with zod, valibot or any Standard Schema.

Source: https://bettersupabase.com/docs/plugins/validation

```ts title="src/lib/supabase/index.ts"
import { validation } from "better-supabase/plugins/validation";

import { validators } from "./generated.zod.ts";

const betterSupabase = defineSupabase(schema).use(
  validation({ schemas: validators }),
);
```

`validators` is generated by `zod()`, `valibot()` or `standardSchema()` (no
validation library needed) and maps each table to
its `insert` and `update` schemas. You can also pass your own, per table:

```ts
validation({
  schemas: {
    customers: { insert: customerForm, update: customerForm.partial() },
  },
});
```

* Inserts and upserts use `insert`; updates use `update`.
* Validation runs on app-cased rows, after the other plugins, and its output
  is what gets written. Transforms such as trimming apply.
* Failures return a `validation` error (422) with Standard Schema issues.
  Bulk writes prefix each path with the row index: `[1, 'color']`.
* Nothing is sent when validation fails.

Any validator that implements [Standard Schema](https://standardschema.dev)
works: zod, valibot, arktype, effect schema and more.