# validation

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

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

When `gen.generators` includes `zod()`, `valibot()` or `standardSchema()` (no
validation library needed), the generated schema validates every write with
the generated `insert` and `update` schemas. Nothing to install:

```ts title="better-supabase.config.ts"
import { defineConfig, zod } from "better-supabase/config";

export default defineConfig({ gen: { generators: [zod()] } });
```

To pass your own schemas, per table, install `validation()` yourself; it
replaces the one the generated schema installed:

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

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

const betterSupabase = defineSupabase(schema).use(
  validation({
    schemas: {
      ...validators,
      customers: { insert: customerForm, update: customerForm.partial() },
    },
  }),
);
```

- Inserts and upserts use `insert`; updates use `update`.
- Validation runs on app-cased rows, after the other extensions, 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.