# Class: ValidationError

Error thrown when input validation fails. Use for invalid parameters, missing required fields, or type mismatches.

## Example[​](#example "Direct link to Example")

```typescript
throw new ValidationError("Statement is required", { context: { field: "statement" } });
throw new ValidationError("maxPoolSize must be at least 1", { context: { value: config.maxPoolSize } });

```

## Extends[​](#extends "Direct link to Extends")

* [`AppKitError`](/appkit/docs/api/appkit/Class.AppKitError.md)

## Constructors[​](#constructors "Direct link to Constructors")

### Constructor[​](#constructor "Direct link to Constructor")

```ts
new ValidationError(message: string, options?: {
  cause?: Error;
  context?: Record<string, unknown>;
}): ValidationError;

```

#### Parameters[​](#parameters "Direct link to Parameters")

| Parameter          | Type                                                              |
| ------------------ | ----------------------------------------------------------------- |
| `message`          | `string`                                                          |
| `options?`         | { `cause?`: `Error`; `context?`: `Record`<`string`, `unknown`>; } |
| `options.cause?`   | `Error`                                                           |
| `options.context?` | `Record`<`string`, `unknown`>                                     |

#### Returns[​](#returns "Direct link to Returns")

`ValidationError`

#### Inherited from[​](#inherited-from "Direct link to Inherited from")

[`AppKitError`](/appkit/docs/api/appkit/Class.AppKitError.md).[`constructor`](/appkit/docs/api/appkit/Class.AppKitError.md#constructor)

## Properties[​](#properties "Direct link to Properties")

### cause?[​](#cause "Direct link to cause?")

```ts
readonly optional cause: Error;

```

Optional cause of the error

#### Inherited from[​](#inherited-from-1 "Direct link to Inherited from")

[`AppKitError`](/appkit/docs/api/appkit/Class.AppKitError.md).[`cause`](/appkit/docs/api/appkit/Class.AppKitError.md#cause)

***

### code[​](#code "Direct link to code")

```ts
readonly code: "VALIDATION_ERROR" = "VALIDATION_ERROR";

```

Error code for programmatic error handling

#### Overrides[​](#overrides "Direct link to Overrides")

[`AppKitError`](/appkit/docs/api/appkit/Class.AppKitError.md).[`code`](/appkit/docs/api/appkit/Class.AppKitError.md#code)

***

### context?[​](#context "Direct link to context?")

```ts
readonly optional context: Record<string, unknown>;

```

Additional context for the error

#### Inherited from[​](#inherited-from-2 "Direct link to Inherited from")

[`AppKitError`](/appkit/docs/api/appkit/Class.AppKitError.md).[`context`](/appkit/docs/api/appkit/Class.AppKitError.md#context)

***

### isRetryable[​](#isretryable "Direct link to isRetryable")

```ts
readonly isRetryable: false = false;

```

Whether this error type is generally safe to retry

#### Overrides[​](#overrides-1 "Direct link to Overrides")

[`AppKitError`](/appkit/docs/api/appkit/Class.AppKitError.md).[`isRetryable`](/appkit/docs/api/appkit/Class.AppKitError.md#isretryable)

***

### statusCode[​](#statuscode "Direct link to statusCode")

```ts
readonly statusCode: 400 = 400;

```

HTTP status code suggestion (can be overridden)

#### Overrides[​](#overrides-2 "Direct link to Overrides")

[`AppKitError`](/appkit/docs/api/appkit/Class.AppKitError.md).[`statusCode`](/appkit/docs/api/appkit/Class.AppKitError.md#statuscode)

## Methods[​](#methods "Direct link to Methods")

### toJSON()[​](#tojson "Direct link to toJSON()")

```ts
toJSON(): Record<string, unknown>;

```

Convert error to JSON for logging/serialization. Sensitive values in context are automatically redacted.

#### Returns[​](#returns-1 "Direct link to Returns")

`Record`<`string`, `unknown`>

#### Inherited from[​](#inherited-from-3 "Direct link to Inherited from")

[`AppKitError`](/appkit/docs/api/appkit/Class.AppKitError.md).[`toJSON`](/appkit/docs/api/appkit/Class.AppKitError.md#tojson)

***

### toString()[​](#tostring "Direct link to toString()")

```ts
toString(): string;

```

Create a human-readable string representation

#### Returns[​](#returns-2 "Direct link to Returns")

`string`

#### Inherited from[​](#inherited-from-4 "Direct link to Inherited from")

[`AppKitError`](/appkit/docs/api/appkit/Class.AppKitError.md).[`toString`](/appkit/docs/api/appkit/Class.AppKitError.md#tostring)

***

### invalidValue()[​](#invalidvalue "Direct link to invalidValue()")

```ts
static invalidValue(
   fieldName: string, 
   value: unknown, 
   expected?: string): ValidationError;

```

Create a validation error for an invalid field value. Note: The actual value is not stored in context for security reasons. Only the value's type is recorded.

#### Parameters[​](#parameters-1 "Direct link to Parameters")

| Parameter   | Type      |
| ----------- | --------- |
| `fieldName` | `string`  |
| `value`     | `unknown` |
| `expected?` | `string`  |

#### Returns[​](#returns-3 "Direct link to Returns")

`ValidationError`

***

### missingEnvVars()[​](#missingenvvars "Direct link to missingEnvVars()")

```ts
static missingEnvVars(vars: string[]): ValidationError;

```

Create a validation error for missing environment variables

#### Parameters[​](#parameters-2 "Direct link to Parameters")

| Parameter | Type        |
| --------- | ----------- |
| `vars`    | `string`\[] |

#### Returns[​](#returns-4 "Direct link to Returns")

`ValidationError`

***

### missingField()[​](#missingfield "Direct link to missingField()")

```ts
static missingField(fieldName: string): ValidationError;

```

Create a validation error for a missing required field

#### Parameters[​](#parameters-3 "Direct link to Parameters")

| Parameter   | Type     |
| ----------- | -------- |
| `fieldName` | `string` |

#### Returns[​](#returns-5 "Direct link to Returns")

`ValidationError`
