Skip to content

Commit

Permalink
Adding docs for exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
hellovai committed Jul 10, 2024
1 parent 0c95452 commit 01672e7
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 1 deletion.
89 changes: 89 additions & 0 deletions docs/docs/calling-baml/error-handling.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
title: "Exceptions"
---

When BAML raises an exception, it will be an instance of a subclass of `BamlError`. This allows you to catch all BAML-specific exceptions with a single `except` block.

## Import path
<CodeGroup>
```python Python
from baml_py.errors import BamlError
```

```typescript TypeScript
import { BamlError } from '@boundaryml/baml/errors'
```

```ruby Ruby
Not available yet
```
</CodeGroup>


## Exceptions

### BamlError

Base class for all BAML exceptions.

<ResponseField
name="error"
type="string"
>
A human-readable error message.
</ResponseField>

### BamlParseError

Subclass of `BamlError`.

Raised when BAML fails to parse a response into a valid object.

<ResponseField
name="raw_llm_response"
type="string"
>
The raw text from the LLM that failed to parse into the expected return type of a function.
</ResponseField>

### BamlLLMError

Subclass of `BamlError`.

Raised when the call to the LLM fails (only raises the last error).

#### BamlRequestError

Subclass of `BamlLLMError`.

Raised when the request to the LLM fails with a non-200 status code.

<ResponseField
name="status_code"
type="int"
>
The status code of the response.

Common status codes are:

- 400: Bad Request
- 401: Unauthorized
- 403: Forbidden
- 404: Not Found
- 429: Too Many Requests
- 500: Internal Server Error
</ResponseField>


#### BamlInvalidResponseError

Subclass of `BamlLLMError`.

Raised when the response from the network request is not in the expected format.

<ResponseField
name="text"
type="string"
>
The body of the response as a string.
</ResponseField>
3 changes: 2 additions & 1 deletion docs/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@
"docs/calling-baml/calling-functions",
"docs/calling-baml/streaming",
"docs/calling-baml/concurrent-calls",
"docs/calling-baml/multi-modal"
"docs/calling-baml/multi-modal",
"docs/calling-baml/error-handling"
]
},
{
Expand Down

0 comments on commit 01672e7

Please sign in to comment.