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:
| Syntax | Description |
|---|---|
{{ var }} | Variable interpolation |
{% for x in list %} | Loops |
{% if condition %} | Conditionals |
{# comment #} | Comments |
Types
See Type System for detailed explanations.
Primitives
string- Textint- Integerfloat- Decimalbool- Boolean
Modifiers
Type?- OptionalType[]- ArrayType | null- Nullable
See Also
- Client Configuration - LLM client setup
- Getting Started - Practical introduction