Skip to main content

The BAML Type System

BAML's type system is the foundation for reliable AI applications. It ensures LLM outputs are always valid and usable.

Core Types​

Primitives​

TypeDescriptionExample
stringText"hello"
intInteger42
floatDecimal3.14
boolBooleantrue

Complex Types​

// Enums - constrained choices
enum Status {
pending
approved
rejected
}

// Classes - structured objects
class User {
name string
email string
age int? // Optional field
}

// Arrays
class Response {
items string[]
users User[]
}

Type Safety at Runtime​

Unlike traditional type systems that only work at compile time, BAML validates types at runtime when the LLM responds:

LLM Output → BAML Parser → Validated Type → Your Code

This is called Schema-Aligned Parsing.

Why This Matters​

  1. No more JSON parsing errors - BAML handles malformed outputs
  2. Guaranteed structure - Your code always receives the expected type
  3. Provider independence - Same types work across OpenAI, Anthropic, etc.

Learn More​