---
title: AI_ToolChoiceViolationError
description: Learn how to handle AI_ToolChoiceViolationError
url: "https://ai-sdk.dev/v5/docs/reference/ai-sdk-errors/ai-tool-choice-violation-error"
docs_index: /llms.txt
---

> For an index of all documentation, see [/llms.txt](/llms.txt).

This error occurs when a `generateText` or `streamText` response does not
satisfy an enforced tool choice. It is thrown when `toolChoice` is set to
`'none'` but the response contains a tool call. With `streamText`, the error is
emitted in the stream. Tool calls returned while `'none'` is selected are not
executed.

## Properties

- `toolChoice`: The effective tool choice that the response did not satisfy
- `finishReason`: The reason why the model finished generating the response
- `provider`: The provider that returned the response
- `modelId`: The model that returned the response
- `content`: The content returned by the model
- `message`: The error message

## Checking for this Error

You can check if an error is an instance of `AI_ToolChoiceViolationError` using:

```typescript
import { ToolChoiceViolationError } from 'ai';

if (ToolChoiceViolationError.isInstance(error)) {
  // Handle the error
}
```

---

For a semantic overview of all documentation, see [/sitemap.md](/sitemap.md)

For an index of all available documentation, see [/llms.txt](/llms.txt)

For agent-facing discovery, including API and MCP surfaces, see [/agents.md](/agents.md)