BAML Documentation

repository·canary·Indexed 27 days ago

https://github.com/boundaryml/baml

BAML is a programming language engineered for building AI agents, featuring a runtime-persistent type system and agent-optimized tools. The documentation covers the BEX Engine asynchronous runtime, the BEX virtual machine, epoch-based garbage collection, and the BEX Heap's semi-space copying memory management. It also includes guides on the BAML compiler's test suite, architecture diagram generation via cargo-stow, and the BexValue unified boundary type for FFI.

Tokens
275.9K
Snippets
781
Records
1.3K
Agent score
91%

What's inside BAML

  1. Overview of UDF (User Defined Functions)

    canary

    The UDF library provides a configuration-driven approach to customizing calculations based on input shape. It is designed to process arbitrary JSON bodies (such as those from OpenAI, Anthropic, or Gemini) using pattern matching and custom formulas.

    Pattern matching is performed via Breadth-First Search (BFS). For each function (override), the immediate children array is processed, and the first matching child is selected. This continues until the path through the override tree is exhausted.

  2. Overview of BAML

    canary

    BAML (Basically A Made-up Language) is a domain-specific language designed to generate structured outputs from Large Language Models (LLMs). It provides a type-safe abstraction for prompt engineering, allowing developers to build reliable Agents, Chatbots with RAG, and data extraction pipelines.

    Key features include:

    • Fast Developer Experience: Prompting directly within the BAML VSCode playground.
    • Type-Safe Outputs: Full type safety and autocomplete, even when streaming structured data.
    • Universal Compatibility: Works with any LLM, any programming language, and any schema.
    • High Performance: State-of-the-art structured outputs that work with both proprietary and OpenSource models.
  3. Overview of baml-bench pipeline

    canary

    baml-bench is an event-driven benchmarking pipeline for BAML. It automates the process of running coding agents against benchmark tasks, collecting detailed 'trophy' reports, deduplicating findings into an issue list, and dispatching fixes.

    The system relies on a symmetric architecture where every stage is a claimable queue on a Convex table, which is then drained by a long-lived Processor that communicates exclusively with a central api service.

  4. Overview of the BEX Engine

    canary
    The BEX Engine is an asynchronous runtime for the BEX virtual machine. It is responsible for coordinating concurrent execution and managing garbage collection. The engine acts as the central mediator between the BexVm (the virtual machine) and sys_types (system operations like file system, network, and LLM operations).
  5. Overview of BAML features

    canary

    BAML (Basically A Made-up Language) is a programming language designed specifically for agents. Key features include:

    • Type System: Similar to Rust, with types that persist at runtime (no any or dangerous casting).
    • Error Handling: Typed and statically analyzed errors.
    • Concurrency: Supports green threads and colorless concurrency similar to Go.
    • Agent-Centric Design: Built-in stdlib for agents and tools designed to prevent garbage outputs.
    • Testing: Built-in eval framework and testing capabilities.
    • Interoperability: Can be run standalone or integrated incrementally into existing codebases (TypeScript, Python, Go, C#, Java, etc.).
  6. Overview of the BEP Feedback Application

    canary
    The BEP Feedback Application is a standalone web application designed to manage BAML Enhancement Proposals (BEPs) and their feedback lifecycle. It is built for real-time collaboration, providing a centralized platform for proposal discussion, AI-assisted analysis, and knowledge consolidation. Key capabilities include versioned proposal management, threaded and inline commenting, decision/issue tracking, and an AI assistant for content analysis.
  7. Overview of @b/pkg-grammar

    canary
    The @b/pkg-grammar package provides the canonical TextMate grammar for the BAML language. It serves as the single source of truth for syntax highlighting across various platforms, including npm, VS Code, GitHub, and Sublime Text. The grammar is authored in TypeScript using tmlanguage-generator and compiled into several formats to support different consumers.
  8. Understand the limitations of traditional LLM extraction

    canary

    When building structured data extraction pipelines using standard LLM SDKs (like OpenAI or Anthropic), developers often encounter several scaling and maintenance challenges:

    • Infrastructure Bloat: Simple extractions evolve into complex functions containing retry logic, exponential backoff, and manual JSON parsing/fixing (e.g., using regex to strip text around JSON blocks).
    • High Testing Costs: Testing extraction logic typically requires live API calls, which increases latency and costs.
    • Multi-model Complexity: Switching between providers (e.g., OpenAI to Anthropic) requires rewriting integration logic due to differing APIs and response formats.
    • Prompt/Schema Fragmentation: Business logic (like Enum definitions for classification) becomes scattered between code-based schemas (Pydantic) and string-based prompts.
    • Observability Gaps: It is difficult to inspect the exact prompt sent, token usage breakdown, or why specific schema fields were missed without building custom logging infrastructure.