Skip to main content

BAML Syntax Reference

This is the complete syntax reference for the BAML language.

Migration in Progress

Additional reference documentation is being migrated from our legacy docs. Check there for topics not yet covered here.

File Structure​

BAML files use the .baml extension and contain:

// Types
enum MyEnum { ... }
class MyClass { ... }

// Functions
function MyFunction(...) -> ReturnType { ... }

// Clients
client<llm> MyClient { ... }

// Tests
test MyTest { ... }

Functions​

function FunctionName(
param1: Type1,
param2: Type2
) -> ReturnType {
client ClientName
prompt #"
Your prompt template here.
Use {{ param1 }} for variables.
"#
}

Prompt Syntax​

Prompts use Jinja2 templating:

SyntaxDescription
{{ var }}Variable interpolation
{% for x in list %}Loops
{% if condition %}Conditionals
{# comment #}Comments

Types​

See Type System for detailed explanations.

Primitives​

  • string - Text
  • int - Integer
  • float - Decimal
  • bool - Boolean

Modifiers​

  • Type? - Optional
  • Type[] - Array
  • Type | null - Nullable

See Also​