Skip to main content

Generator Block

The generator block tells baml-cli generate how to generate code for your target language. You can define multiple generators to output code for different languages.

tip

If you created your project using baml-cli init, a generator has already been created for you.

Syntax​

generator target {
output_type "<language>"
output_dir "<path>"
version "<version>"
// language-specific options...
}

Language Examples​

generator target {
output_type "python/pydantic"

// Where the generated code will be saved (relative to baml_src/)
output_dir "../"

// What interface to export at top level (sync/async)
// Both are generated regardless
default_client_mode "sync"

// Version of runtime (should match installed baml-py version)
version "0.76.2"
}

Options​

OptionTypeRequiredDescription
output_typestringYesTarget language/framework
output_dirstringYesOutput path (relative to baml_src/)
versionstringYesRuntime version to target
default_client_mode"sync" | "async"NoDefault export mode
module_format"esm" | "cjs"NoTypeScript module format
client_package_namestringNoGo module name
on_generatestringNoCommand to run after generation

Output Types​

TypeDescription
python/pydanticPython with Pydantic 2.x
python/pydantic/v1Python with Pydantic 1.x
typescriptTypeScript
typescript/reactTypeScript with React hooks
goGo
ruby/sorbetRuby with Sorbet types (beta)
rest/openapiOpenAPI specification

See Also​