Most AI engineers use LLMs to get structured outputs (e.g. a json schema) from unstructured inputs (strings). For example, to extract a resume from a chunk of text.
Existing LLM python libraries aren't powerful enough for structured prompting nor do they have easy testing capabilities (see our comparisons with other frameworks, like Pydantic) -- so we decided to build a compiler.
BAML (Basically, A Made-Up Language) is a lightweight programming language to define AI functions with structured inputs and outputs using natural language.
The BAML VSCode Playground allows you to test prompts instantly with any LLM, without ever leaving VSCode.
1mindemo.mp4
Alt video link
Here’s a .baml
AI function:
// example.baml
class Resume {
name string
skills string[]
}
function ExtractResume {
input (resume_text: string)
output Resume[]
}
impl<llm, ExtractResume> version1 {
client GPT4Client // client definition not shown
prompt #"
(see the syntax highlighted prompt in the video)
"#
}
(We have better syntax highlighting in VSCode)
BAML compiles to fully typed Python and TypeScript. No matter how you change the prompt, or the LLM model, or fail-overs, the python code doesn’t change — unless you change your AI function’s signature.
# app.py
from baml_client import baml as b
async def main():
resume = await b.ExtractResume(resume_text="""John Doe
Python, Rust
University of California, Berkeley, B.S.
in Computer Science, 2020""")
assert resume.name == "John Doe"
BAML can be deployed to any container, with only a single package dependency required (e.g. pip install baml
).
Start by installing BAML and reading our Hello World Tutorial.
Learning a new language may seem daunting, but it takes < 10 minutes to get started.
The VSCode extension provides auto-compiling on save, a realtime preview of the full prompt, syntax highlighting and great errors — every syntax error recommends a fix.
Making BAML easy to read and write is our core design philosophy.
- Typed Python/Typescript support
- VSCode Playground: see the full prompt and run tests
- Better code organization — no scattered jinja templates or yaml files
- Its fast! BAML compiles into PY and TS in less than 50ms (We ❤️ Rust)
- Full integration with Boundary Studio - our observability dashboard
- Turn live production data into a test-case with one click!
- Get structured responses, 11 natively supported types, including custom classes
- Hallucination Checks, when LLMs return something unexpected, we throw an exception
- Works with any LLM, even your own
- And best of all, everything lives in your codebase.
See more at our docs page
Please do not file GitHub issues or post on our public forum for security vulnerabilities, as they are public!
Boundary takes security issues very seriously. If you have any concerns about BAML or believe you have uncovered a vulnerability, please get in touch via the e-mail address [email protected]. In the message, try to provide a description of the issue and ideally a way of reproducing it. The security team will get back to you as soon as possible.
Note that this security address should be used only for undisclosed vulnerabilities. Please report any security problems to us before disclosing it publicly.