Skip to main content

BamlValidationError

Thrown when BAML fails to parse or validate LLM output against the expected schema.

Type Definition​

class BamlValidationError extends Error {
type: 'BamlValidationError'
message: string
prompt: string
raw_output: string
detailed_message: string
}

Properties​

PropertyTypeDescription
type'BamlValidationError'Literal type identifier
messagestringSpecific validation failure description
promptstringOriginal prompt sent to LLM
raw_outputstringRaw LLM output that failed validation
detailed_messagestringComplete history of failed attempts (for fallback/retry)

Detection​

import { BamlValidationError } from '@boundaryml/baml'

try {
const result = await b.ExtractUser(text)
} catch (error) {
if (error instanceof BamlValidationError) {
console.log('Validation failed:', error.message)
console.log('Raw output:', error.raw_output)
console.log('Prompt used:', error.prompt)
}
}

Common Causes​

  • LLM output doesn't match expected JSON structure
  • Missing required fields in output
  • Type mismatches (e.g., string instead of number)
  • Enum values not in allowed list
  • Array/object structure doesn't match schema

Debugging Tips​

  1. Check raw_output to see what the LLM actually returned
  2. Review prompt to ensure output format instructions are clear
  3. Use detailed_message when debugging fallback chains

See Also​