BamlValidationError

The BamlValidationError class represents an error that occurs when BAML fails to parse or validate LLM output.

Type Definition

Type Definition
1class BamlValidationError extends Error {
2 type: 'BamlValidationError'
3 message: string
4 prompt: string
5 raw_output: string
6 detailed_message: string
7}

Properties

type
'BamlValidationError'

Literal type identifier for the error class.

message
string

Error message describing the specific validation failure.

prompt
string

The original prompt sent to the LLM.

raw_output
string

The raw output from the LLM that failed validation.

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
1if (error instanceof BamlValidationError) {
2 // Handle validation error
3}