Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding docs for exceptions #770

Merged
merged 6 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading