What is baml_client?

baml_client is the code that gets generated from your BAML files that transforms your BAML prompts into the same equivalent function in your language, with validated type-safe outputs.

Python
from baml_client import b
resume_info = b.ExtractResume("....some text...")

This has all the boilerplate to:

  1. call the LLM endpoint with the right parameters,
  2. parse the output,
  3. fix broken JSON (if any)
  4. return the result in a nice typed object.
  5. handle errors

In Python, your BAML types get converted to Pydantic models. In Typescript, they get converted to TypeScript types, and so on. BAML acts like a universal type system that can be used in any language.

Generating baml_client

Refer to the Installation guides for how to set this up for your language, and how to generate it.

But at a high-level, you just include a generator block in any of your BAML files.

generator target {
// Valid values: "python/pydantic", "typescript", "ruby/sorbet", "go"
output_type "python/pydantic"
// Where the generated code will be saved (relative to baml_src/)
output_dir "../"
// What interface you prefer to use for the generated code (sync/async)
// Both are generated regardless of the choice, just modifies what is exported
// at the top level
default_client_mode "sync"
// Version of runtime to generate code for (should match installed baml-py version)
version "0.203.1"
}

The baml_client transforms a BAML function into the same equivalent function in your language,