All we wanted was our prompts in our codebase, not on some website. Then just to see the prompts before we ran the code. Then comments inside of prompts. Then just less strings everywhere, and more type-safety...
At some point, it became BAML: a type-safe, self-contained way to call LLMs from Python and/or TypeScript.
BAML encapsulates all the boilerplate for:
- flexible parsing of LLM responses into your exact data model
- streaming LLM responses as partial JSON
- wrapping LLM calls with retries and fallback strategies
Our VSCode extension provides:
- real-time prompt previews,
- an LLM testing playground, and
- syntax highlighting (of course)
Here's a short BAML snippet for extracting a resume (with syntax highlighting):
Or in code form:
// extract_resume.baml
// 1. Define the type for the output
class Resume {
name string
// Use an array to get multiple education histories
education Education[]
}
// A nested class
class Education {
university string
start_year int
// @description injects context into the prompt about this field
end_year int?
@description("unset if still in school")
}
// 2. Define the function signature
// This function takes in a single paramater
// Outputs a Resume type
function ExtractResume {
input (resume_text: string)
output Resume
}
// 3. Use an llm to implement ExtractResume.
// We'll name this impl 'version1'.
impl<llm, ExtractResume> version1 {
client GPT4
prompt #"
Extract the resume from:
###
{// This macro injects your input param //}
{#input.resume_text}
###
Output JSON Schema:
{// This macro prints out your schema //}
{#print_type(output)}
"#
}
The whole premise really just boils down to:
- preferring to use types, not strings
- not wanting to leave VSCode just to do some LLM testing
We also have a bunch of cool features in the works: conditionals and loops in our prompt templates, image support, and more powerful types.
We're still pretty early and would love to hear your feedback. To get started:
Top comments (0)