FrameworksAgentic

BAML Documentation — Structured Outputs from Any LLM

by Boundary (BoundaryML)

IntermediateDocumentationFree~2-4 hours to get a typed LLM function running inside your own codebase

Declare the schema, get typed outputs — even when the model returns broken JSON.

Start LearningAdded Aug 1, 2026 · Updated Aug 25, 2026

Overview

BAML, which the repository glosses as "Basically A Made-up Language", is an Apache-2.0 DSL from Boundary in Seattle (9k-plus GitHub stars, Rust core) for writing LLM calls as typed declarations rather than f-strings. You declare classes, enums and a function signature in a .baml file; the toolchain generates a fully typed client you call from Python, TypeScript, Go, Java and other host languages, and the runtime absorbs provider differences, retries and fallbacks. The core technical idea is Schema-Aligned Parsing (SAP): instead of relying on JSON mode or provider function-calling to constrain generation up front, BAML lets the model answer naturally and then coerces the output onto the declared schema using custom edit-distance algorithms, fixing missing quotes, trailing commas, comments, markdown code fences and reasoning preambles. Boundary's published Berkeley Function Calling Leaderboard comparison reports SAP at 92% on gpt-3.5-turbo against 87.5% for function calling, 93% on gpt-4o against 87.4%, 91.7% on claude-3-haiku against 57.3%, and 92.4% on gpt-4o-mini against 19.8% — these are vendor-run numbers, so treat them as directional. The docs also cover semantic streaming with @stream.done and @stream.with_state annotations for type-safe partial results, and a VS Code playground that renders the exact prompt with token counts and runs regression test cases without standing up a Python environment. One versioning caveat worth knowing before you start: docs.boundaryml.com documents BAML v0, the DSL described here, while BAML v1 — a broader language with a Rust-like type system, green threads, typed error handling and an agent standard library — is in public beta and documented separately.

At a Glance

Topic
Frameworks
Level
Intermediate
Format
Documentation
Cost
Free
Duration
~2-4 hours to get a typed LLM function running inside your own codebase
Provider
Boundary (BoundaryML)
Hands-on
Yes — code/exercises
Certificate
None

What You’ll Learn

  • Declare LLM functions with typed classes and enums in .baml files
  • Generate fully typed clients for Python, TypeScript, Go and Java
  • Understand how Schema-Aligned Parsing repairs malformed model output
  • Preview the exact rendered prompt and token count before spending API calls
  • Write and run prompt regression tests inside the VS Code playground
  • Stream partial structured results safely using stream state annotations
  • Configure retries, fallbacks and multiple providers behind a single function

Highlights

  • Parses what the model actually said instead of constraining what it may say
  • Works with providers that have no function-calling support, including open models
  • Typed clients in several host languages generated from one schema definition
  • Playground testing runs without standing up a Python environment first
  • Claims roughly 80% fewer schema tokens than the equivalent JSON Schema definition

Who It’s For

Best For

  • Teams extracting structured data from documents or unstructured text
  • Polyglot codebases needing one prompt definition across several languages
  • Engineers hitting the limits of JSON mode and provider function calling
  • Anyone who wants prompt changes covered by tests rather than by hope

Prerequisites

  • Comfortable adding a code-generation step to your build pipeline
  • Working knowledge of one supported host language and its type system
  • An API key for at least one LLM provider to run real calls

FAQ

What is BAML Documentation — Structured Outputs from Any LLM?

Documentation for BAML, Boundary's domain-specific language for defining LLM calls as typed functions instead of format strings. Its Schema-Aligned Parsing algorithm repairs imperfect model output — markdown-wrapped JSON, trailing commas, chain-of-thought preambles, unescaped characters — rather than rejecting it, and generates fully typed clients for several host languages. A VS Code playground previews the exact rendered prompt and runs saved tests without leaving the editor.

Is BAML Documentation — Structured Outputs from Any LLM free?

BAML Documentation — Structured Outputs from Any LLM is free to access.

What level is BAML Documentation — Structured Outputs from Any LLM for?

BAML Documentation — Structured Outputs from Any LLM is aimed at a intermediate audience. Recommended background: Comfortable adding a code-generation step to your build pipeline, Working knowledge of one supported host language and its type system, An API key for at least one LLM provider to run real calls.

How long does BAML Documentation — Structured Outputs from Any LLM take?

Expect roughly ~2-4 hours to get a typed LLM function running inside your own codebase. Most learners work through it at their own pace.

What will I learn from BAML Documentation — Structured Outputs from Any LLM?

You'll learn: Declare LLM functions with typed classes and enums in .baml files; Generate fully typed clients for Python, TypeScript, Go and Java; Understand how Schema-Aligned Parsing repairs malformed model output; Preview the exact rendered prompt and token count before spending API calls; Write and run prompt regression tests inside the VS Code playground; Stream partial structured results safely using stream state annotations; Configure retries, fallbacks and multiple providers behind a single function.

Topics

structured-outputsdslprompt-engineeringtype-safetybaml

Sources

This page was written from 4 sources, 2 on domains other than docs.boundaryml.com.

  1. 1.docs.boundaryml.comhomevendor
  2. 2.docs.boundaryml.comwhy bamlvendor
  3. 3.github.combaml
  4. 4.boundaryml.comschema aligned parsing