Skip to main content

Installation Steps

1

Install BAML VSCode/Cursor Extension

Install the extension from: https://marketplace.visualstudio.com/items?itemName=boundary.baml-extensionFeatures include:
  • Syntax highlighting
  • Testing playground
  • Prompt previews
For better autocomplete in Python (not just BAML), add this to your VSCode User Settings:
{
  "python.analysis.typeCheckingMode": "basic"
}
2

Install BAML

Install the baml-py package using your preferred package manager:
pip install baml-py
3

Initialize BAML in Your Project

This creates a baml_src directory with starter BAML code:
baml-cli init
4

Generate the baml_client Module

One of the files in your baml_src directory will have a generator block. Run this command to auto-generate the baml_client directory with Python code to call your BAML functions.Any types defined in .baml files will be converted into Pydantic models.
baml-cli generate
If you have the VSCode extension installed, it will automatically run baml-cli generate when you save a BAML file.
5

Use BAML Functions in Python

Import and use your generated BAML client:
from baml_client.sync_client import b
from baml_client.types import Resume

def example(raw_resume: str) -> Resume: 
  # BAML's internal parser guarantees ExtractResume
  # to always return a Resume type
  response = b.ExtractResume(raw_resume)
  return response

def example_stream(raw_resume: str) -> Resume:
  stream = b.stream.ExtractResume(raw_resume)
  for msg in stream:
    print(msg)  # PartialResume type
  
  # Final response is a Resume type
  final = stream.get_final_response()
  return final

Using BAML with Jupyter Notebooks

To use BAML in Jupyter notebooks and have your changes automatically reflected:
1

Setup the Autoreload Extension

%load_ext autoreload
%autoreload 2
This ensures the baml_client module reloads before every cell runs.
2

Import as a Module

Instead of using from baml_client import b, import the module directly:
# Assuming your baml_client is inside a dir called app/
import app.baml_client as client  # you can name this "llm" or "baml" or whatever you want
The %autoreload extension doesn’t work well with from...import statements.
3

Call BAML Functions with Module Prefix

raw_resume = "Here's some resume text"
client.b.ExtractResume(raw_resume)
Now your changes in .baml files are reflected automatically without restarting the kernel.
Pylance will complain about schema changes you make in .baml files. You can ignore these errors. If you want it to pick up new types, you’ll need to restart the kernel. This auto-reload approach works best if you’re only making changes to prompts.

Build docs developers (and LLMs) love