---
url: >-
  https://adk.nht.io/api/@nhtio/adk/batteries/sandbox/functions/validateOrThrow.md
---

# Function: validateOrThrow()

```ts
function validateOrThrow<T>(
  schema: Schema,
  value: unknown,
  convert?: boolean,
): T;
```

Defined in: [src/lib/utils/validation.ts:113](https://github.com/NHTIO/ADK/blob/v1.20260824.1/src/src/lib/utils/validation.ts#L113)

Validates `value` against `schema` synchronously and returns the coerced result typed as `T`.

## Type Parameters

| Type Parameter | Description                                               |
| -------------- | --------------------------------------------------------- |
| `T`            | The expected type of `value` after successful validation. |

## Parameters

| Parameter | Type      | Default value | Description                                                                                                                                            |
| --------- | --------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `schema`  | `Schema`  | `undefined`   | The schema to validate against.                                                                                                                        |
| `value`   | `unknown` | `undefined`   | The value to validate.                                                                                                                                 |
| `convert` | `boolean` | `false`       | When `true`, the validator coerces values to their target types (e.g. string `"1"` → number `1`). Defaults to `false` to prevent silent type coercion. |

## Returns

`T`

The validated (and optionally coerced) value typed as `T`.

## Remarks

Collects all field errors before throwing. Use [asyncValidateOrThrow](asyncValidateOrThrow.md) for schemas that
include async custom validators.

## Throws

ValidationException when `value` does not satisfy `schema`.
