What is BAML?

The best way to understand BAML and its developer experience is to see it live in a demo (see below).

Demo video

Here we write a BAML function definition, and then call it from a Python script.

Examples

High-level Developer Flow

1

Write a BAML function definition

main.baml
1class WeatherAPI {
2 city string @description("the user's city")
3 timeOfDay string @description("As an ISO8601 timestamp")
4}
5
6function UseTool(user_message: string) -> WeatherAPI {
7 client "openai/gpt-4o"
8 prompt #"
9 Extract.... {# we will explain the rest in the guides #}
10 "#
11}

Here you can run tests in the VSCode Playground.

2

Generate baml_client from those .baml files.

This is auto-generated code with all boilerplate to call the LLM endpoint, parse the output, fix broken JSON, and handle errors.

3

Call your function in any language

with type-safety, autocomplete, retry-logic, robust JSON parsing, etc..

1import asyncio
2from baml_client import b
3from baml_client.types import WeatherAPI
4
5def main():
6 weather_info = b.UseTool("What's the weather like in San Francisco?")
7 print(weather_info)
8 assert isinstance(weather_info, WeatherAPI)
9 print(f"City: {weather_info.city}")
10 print(f"Time of Day: {weather_info.timeOfDay}")
11
12if __name__ == '__main__':
13 main()

Continue on to the Installation Guides for your language to setup BAML in a few minutes!

You don’t need to migrate 100% of your LLM code to BAML in one go! It works along-side any existing LLM framework.