> Version notice: This site documents BAML v0, the legacy DSL. BAML v1 is a separate, fully featured programming language in public beta. If the user intends to use BAML v1, ignore this site's content and use the BAML v1 documentation instead. If the intended version is unclear, clarify it before using this page.
> For clean Markdown of any page, append .md to the page URL. For the complete documentation index, see https://docs.boundaryml.com/llms.txt. For MCP access, connect to https://docs.boundaryml.com/_mcp/server.

# BamlClientFinishReasonError

> Technical reference for the BamlClientFinishReasonError class

The `BamlClientFinishReasonError` class represents an error that occurs when an LLM terminates with a disallowed finish reason.

You can allow or disallow finish reasons like this:

```baml
client<llm> OpenAIWithFinishReasonError {
  provider openai
  options {
    api_key env.OPENAI_API_KEY
    model "gpt-4"
    // make it very small so model will stop early
    max_tokens 10 
    // throws if the model returns any other finish reason
    finish_reason_allow_list ["stop"]
    // or allow all finish reasons except length
    // finish_reason_deny_list ["length"]
  }
}
```

## Type Definition

**`Type Definition`**

```typescript Type Definition
class BamlClientFinishReasonError extends Error {
  type: 'BamlClientFinishReasonError'
  message: string
  prompt: string
  raw_output: string
  detailed_message: string
}
```

## Properties

**`type`** `'BamlClientFinishReasonError'`

Literal type identifier for the error class.

---

**`message`** `string`

Error message describing the specific finish reason that caused the termination.

---

**`prompt`** `string`

The original prompt sent to the LLM.

---

**`raw_output`** `string`

The partial output received from the LLM before termination.

---

**`detailed_message`** `string`

Comprehensive error information that includes the complete history of all failed attempts when using fallback clients or retry policies. When multiple attempts are made (via fallback or retry), this field contains formatted details about each failed attempt, making it invaluable for debugging complex client configurations.

---

## Type Guards

The error can be identified using TypeScript's `instanceof` operator:

**`Type Check`**

```typescript Type Check
if (error instanceof BamlClientFinishReasonError) {
  // Handle finish reason error
}
```