BAML (BoundaryML) For Structured AI Outputs

NAME

baml - a domain-specific language to transform unstructured data with LLMs into structured outputs

SYNOPSIS

baml treats prompts as functions, enabling typed inputs, schema validation, and robust parsing. It is model-agnostic, letting you parse text, images, or audio via any LLM that supports those modalities. The resulting pipeline is fully typed and strongly validated.

DESCRIPTION

BAML (BoundaryML) is an open-source toolkit for developers who want reliable, structured output from large language models (LLMs). It works by defining a .baml file containing:

function ExtractResume(
    resumeText: string
) -> Resume {
    """Analyze the given resume text and extract:
    - fullName (string)
    - skills (list of strings)
    """
    {{resumeText}}
}
        

Once compiled, it generates typed client code (Python, TypeScript, etc.) that automatically calls the underlying LLM and corrects minor format errors to match the specified schema. For instance, if the LLM outputs nearly valid JSON with missing quotes, BAML's parser patches it into valid JSON. This drastically reduces errors and cuts the cost of prompting.

You can also handle images or audio if your LLM supports multi-modal inputs. BAML simply references them in your function parameters, then includes them in the prompt behind the scenes.

EXAMPLES

1. Static Extraction: Suppose you have raw text logs. You can define a .baml prompt that extracts LogEntry objects:

function ParseLog(
    rawLog: string
) -> LogEntry {
    """Given a log entry, return {level, timestamp, message}."""
    {{rawLog}}
}
        

After compilation, calling parseLog(rawString) yields a typed LogEntry object even if the LLM's JSON was slightly malformed.

2. Image Description: If the LLM can process images, BAML can embed them:

function DescribeImage(
    photo: image
) -> string {
    """Return a short description of the image."""
    {{photo}}
}
        

This simplifies multi-modal AI tasks (e.g., receipt scanning or vision Q&A).

SEE ALSO

Back to Blog Index | Main Terminal

For details: BoundaryML/baml
Or read the official docs at boundaryml.com