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
1from baml_client import b
2resume_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.

1generator target {
2 // Valid values: "python/pydantic", "typescript", "ruby/sorbet"
3 output_type "python/pydantic"
4
5 // Where the generated code will be saved (relative to baml_src/)
6 output_dir "../"
7
8 // What interface you prefer to use for the generated code (sync/async)
9 // Both are generated regardless of the choice, just modifies what is exported
10 // at the top level
11 default_client_mode "sync"
12
13 // Version of runtime to generate code for (should match installed baml-py version)
14 version "0.54.0"
15}

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