BAML
Type: full-code · Vendor: Boundary (BoundaryML) · Language: Rust · License: Apache-2.0 · Status: active · Status in practice: emerging · First released: 2023-10-01
BAML is a domain-specific language for writing LLM functions that return type-safe structured outputs and are version-controlled and testable alongside application code.
Description. BAML is a domain-specific language for defining and testing LLM functions. Each prompt becomes a typed function that produces structured outputs from an LLM, with generated client code that calls the endpoint, parses the output, fixes broken JSON, and handles errors. Prompts are version controlled with the application code and can be viewed and run directly within the editor. BAML works across model providers, including open-source models, and is released under Apache 2.0.
Agent loop shape. A developer declares an LLM function in BAML with a typed return shape and prompt. BAML generates client code that sends the prompt to the configured model, parses the response, repairs malformed JSON, and returns a typed value to the application. The function can be run and tested directly in the editor, and lives in source control with the rest of the code.
Primary use cases
- defining LLM functions as typed code
- extracting type-safe structured outputs from LLMs
- version-controlling and testing prompts with application code
- running prompts directly in the editor
Key concepts
- LLM function → own-your-prompts (docs) — BAML's central unit: a named function with typed parameters, a typed return shape, a client, and a prompt template, compiled into a generated client your application calls like an ordinary function.
- Schema-Aligned Parsing (SAP) → structured-output (docs) — BAML's Rust parser that reads whatever the model returns and coerces it into the declared schema, fixing markdown fences, trailing commas, and unquoted values instead of requiring strictly valid JSON.
- baml_client → structured-output (docs) — The generated client package BAML emits for your target language (Python, TypeScript, Ruby, Go, and more) that wraps each LLM function with type-safe call, parse, and error handling.
- test block → eval-harness (docs) — An in-file test case for an LLM function with fixed inputs and @@assert / @@check expectations, runnable in the VSCode/JetBrains playground or via the BAML CLI.
Patterns this full-code implements —
- ★Own Your Prompts (12-Factor Agents)
BAML makes every prompt a typed function defined in source files in the application repo, version-controlled with the code and testable in-editor, so prompts are owned and tested by the team rather t…
- ★★Structured Output
BAML's purpose is generating structured outputs from LLMs: every LLM function declares a typed return shape, and the generated client parses the model output into that type with Schema-Aligned Parsin…
- ★★Provider Fallback
A BAML client can be declared as a fallback strategy over an ordered list of provider clients; if the first provider fails, the generated client tries the next, so a function can fail over across mod…
- ★★Eval Harness
BAML functions carry test blocks that run the function against a model with fixed inputs and check the result with @@assert / @@check; tests run in the editor playground or from the CLI, so prompt ch…
Neighbourhood
Click any neighbour to follow the lineage. Scroll to zoom, drag to pan.