fern/01-guide/what-is-baml_client.mdx
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.
from baml_client import b
resume_info = b.ExtractResume("....some text...")
This has all the boilerplate to:
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.
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.
<CodeBlocks>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"
}
generator target {
// Valid values: "python/pydantic", "typescript", "ruby/sorbet", "go"
output_type "typescript"
// 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 "async"
// Version of runtime to generate code for (should match the package @boundaryml/baml version)
version "0.203.1"
}
generator target {
// Valid values: "python/pydantic", "typescript", "ruby/sorbet", "go"
output_type "go"
// Where the generated code will be saved (relative to baml_src/)
output_dir "../"
// Version of runtime to generate code for (should match installed github.com/boundaryml/baml version)
version "0.203.1"
// Go module name for the generated client
client_package_name "example.com/myproject"
// Commands to run after code generation (mandatory as it cleans up the generated code)
on_generate "gofmt -w . && goimports -w . && go mod tidy"
}
generator target {
// Valid values: "python/pydantic", "typescript", "ruby/sorbet", "go"
output_type "ruby/sorbet"
// Where the generated code will be saved (relative to baml_src/)
output_dir "../"
// Version of runtime to generate code for (should match installed `baml` package version)
version "0.203.1"
}
generator target {
// Valid values: "python/pydantic", "typescript", "ruby/sorbet", "go", "rest/openapi"
output_type "rest/openapi"
// Where the generated code will be saved (relative to baml_src/)
output_dir "../"
// Version of runtime to generate code for (should match installed `baml` package version)
version "0.203.1"
// 'baml-cli generate' will run this after generating openapi.yaml, to generate your OpenAPI client
// This command will be run from within $output_dir
on_generate "npx @openapitools/openapi-generator-cli generate -i openapi.yaml -g OPENAPI_CLIENT_TYPE -o ."
}
The baml_client transforms a BAML function into the same equivalent function in your language,