Skip to main content

Types Overview

BAML provides a rich type system for defining inputs and outputs of AI functions.

Primitive Types​

TypeDescription
boolBoolean value (true or false)
intInteger number
floatFloating point number
stringText data
nullNull/empty value

Composite Types​

TypeSyntaxDescription
classclass Name { ... }User-defined structured data
enumenum Name { ... }Set of named constants
arrayType[]Collection of elements
mapmap<KeyType, ValueType>Key-value pairs
optionalType?Value that may be absent
unionType1 | Type2One of several types
literal"value" or 1 or trueSpecific constrained value
type aliastype Name = TypeAlternative name for a type

Multimodal Types​

TypeDescription
imageImage data (URL or base64)
audioAudio data (URL or base64)
pdfPDF document (base64 only)
videoVideo data (URL or base64)

Type Examples​

// Primitives
function GetCount() -> int { ... }
function GetName() -> string { ... }

// Arrays
function GetNames() -> string[] { ... }

// Optional
function GetAge() -> int? { ... }

// Union
function Classify() -> "bug" | "feature" | "question" { ... }

// Complex
class Person {
name string
age int?
tags string[]
}

function ParsePerson(text: string) -> Person { ... }

Unsupported Types​

TypeAlternative
any/jsonUse string and parse manually, or use dynamic types
datetimeUse string
durationUse string with ISO8601 format
setUse array (Type[])
tupleUse class

See Also​