Skip to main content
BAML supports five primitive types that form the foundation of the type system.

String

String types represent text data. BAML supports three string formats:

Quoted Strings

Inline strings surrounded by double quotes, similar to strings in most programming languages.
"Hello World"
"\n"  // Escaped characters supported
Quoted strings cannot contain template variables or expressions. Use block strings for that.

Unquoted Strings

Simple inline strings without quotes, useful for configuration values.
Hello World
Restrictions: Unquoted strings may not contain:
  • Quotes (“double” or ‘single’)
  • At-signs @
  • Curlies
  • Hashtags #
  • Parentheses ()
  • Brackets []
  • Commas ,
  • Newlines

Block Strings

Multi-line strings surrounded by #" and "#, automatically dedented and stripped of first/last newlines.
#"
Hello
World
"#
Block strings support Jinja templating:
template_string Greeting(name: string) #"
  Hello {{ name }}!
"#
Escape Characters: Use \n to include literal escape sequences. Including "# in content: Prefix with more # symbols:
###"
  #"Hello"#
"###

Integer (int)

Whole numbers without decimal points.
int
integer
Represents whole numbers (positive, negative, or zero)
function DescribeCircle(radius: int) -> string {
    client "openai/gpt-4o-mini"
    prompt #"
        Describe a circle with a radius of {{ radius }} units.
    "#
}

Generated Types

# Type: int
radius: int = 5

Float (float)

Floating-point numbers with decimal precision.
float
number
Represents decimal numbers with floating-point precision
function CalculateArea(pi: float) -> string {
    client "openai/gpt-4o-mini"
    prompt #"
        Calculate using pi as {{ pi }}.
    "#
}
BAML supports implicit casting of intfloat, but to explicitly ensure a float value, use 0.0 instead of 0.

Generated Types

# Type: float
pi: float = 3.14159

Boolean (bool)

True or false values.
bool
boolean
Represents true/false values
function CreateStory(long: bool) -> string {
    client "openai/gpt-4o-mini"
    prompt #"
        Write a story that is {{ "10 paragraphs" if long else "1 paragraph" }} long.
    "#
}

test LongStory {
    functions [CreateStory]
    args { long true }
}

test ShortStory {
    functions [CreateStory]
    args { long false }
}

Generated Types

# Type: bool
long: bool = True

Null

Represents the absence of a value.
null
null
Represents a null/nil/None value
type NullableString = string | null

Generated Types

# Type: None
value: None = None

Combined Example

Using multiple primitive types together:
function DescribeCircle(radius: int | float, pi: float?, includeArea: bool) -> string {
    client "openai/gpt-4o-mini"
    prompt #"
        Describe a circle with a radius of {{ radius }} units.
        {% if includeArea %}
        Include the area of the circle using pi as {{ pi or 3.14159 }}.
        {% endif %}
        
        What are some properties of the circle?
    "#
}

test CircleDescription {
    functions [DescribeCircle]
    args { 
        radius 5.0
        pi 3.14
        includeArea true
    }
}

Type Casting

Implicit Casting
int → float
Integers can be implicitly cast to floats
// This works - int is cast to float
function Example(value: float) -> string {
    // ...
}

test TestCasting {
    functions [Example]
    args { value 5 }  // 5 (int) is cast to 5.0 (float)
}
Order matters in union types. "1" will be parsed as:
  • int when type is int | string
  • string when type is string | int

Build docs developers (and LLMs) love