BAML Error Types
BAML provides a set of error classes for handling different error scenarios when working with LLMs. Each error type is designed to handle specific failure cases in the BAML runtime.
Error Class Hierarchy
All BAML errors extend the base JavaScript Error
class and include a literal type
field for type identification.
Error Types
BamlValidationError
Thrown when BAML fails to parse or validate LLM output. Contains the original prompt and raw output for debugging.
BamlClientFinishReasonError
Thrown when an LLM terminates with a disallowed finish reason. Includes the original prompt and partial output received before termination.
BamlAbortError
Thrown when a BAML operation is cancelled via an abort controller. Contains an optional reason for the cancellation.
Fallback Error Aggregation
When using fallback clients or clients with retry policies, BAML attempts multiple client calls before finally failing. In these cases:
- The error type corresponds to the final (last) failed attempt
- The
message
field contains the error message from the final attempt - The
detailed_message
field contains the complete history of all failed attempts
This allows you to debug the entire fallback chain while still getting a specific error type for the final failure.
Type Guards
All BAML errors can be identified using TypeScript’s instanceof
operator:
Common Properties
All BAML error classes include:
Literal type identifier specific to each error class.
Human-readable error message describing the failure.
Comprehensive error information that includes the complete history of all failed attempts when using fallback clients or retry policies. For single attempts, this typically contains the same information as message
but may include additional debugging details.
For detailed information about each error type, refer to their individual reference pages.