BAML (Basically a Made-up Language) is a domain-specific language and toolchain designed to build reliable AI workflows and agents by transforming prompt engineering into schema engineering. It generates type-safe client code for Python (and other languages like TypeScript, Ruby, Go), enabling structured outputs from Large Language Models with built-in features like streaming, retries, and broad model support. The library is actively maintained with frequent releases, currently at version 0.220.0.
pip install baml-pyVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `baml-py` after initializing a BAML project and generating client code. First, install `baml-py` and use `baml-cli init` to create a `baml_src` directory with example BAML functions (e.g., `ExtractResume` defined in a `.baml` file). Then, run `baml-cli generate` to create the `baml_client` Python module. The generated client (`b`) allows you to call your BAML-defined functions directly from Python with type-safety. Ensure necessary LLM API keys (e.g., `OPENAI_API_KEY`) are set in your environment.
After upgrading `baml-py`, update the `version` field in `generators.baml` and ensure your `baml-cli` and VSCode extension are also updated to match. Rerun `baml-cli generate`.
Define or modify your LLM functions, schemas, and clients only within the `.baml` files in your `baml_src` directory. The `baml_client` will be updated automatically.
Ensure all required environment variables are set in your execution environment or loaded via `python-dotenv`. For local development, check the playground settings in the VSCode extension.
Use `%load_ext autoreload` and `%autoreload 2` at the start of your notebook. Then, import the `baml_client` module directly (e.g., `import app.baml_client as client`) and call functions with the module prefix (e.g., `client.b.ExtractResume(...)`).
Always include `{{ ctx.output_format }}` at the end of your BAML function's prompt string.