baml generate command processes your BAML source files and generates type-safe client code in your target language(s).
Usage
Options
Path to the directory containing your BAML source files.
Skip version compatibility check between the CLI and generator configuration.Warning: Using mismatched versions may cause runtime errors or unexpected behavior.
Strip test blocks from the generated client code to reduce file size.Useful for production builds where tests are not needed at runtime. The generated client will be smaller but test definitions won’t be available for introspection.
Enable specific features (can be specified multiple times).Available features:
beta- Enable beta features and suppress experimental warningsdisplay_all_warnings- Show all warnings in CLI output
What It Does
When you runbaml generate, the command:
-
Parses BAML files - Reads all
.bamlfiles in yourbaml_srcdirectory -
Validates configuration - Checks that generator configurations in
generators.bamlmatch the CLI version -
Generates clients - Creates type-safe client code for each generator configuration, including:
- Function signatures matching your BAML definitions
- Type definitions for classes and enums
- Client implementations for sync/async execution
- Embedded BAML source for runtime introspection
-
Runs post-generation hooks - Executes
on_generatecommands specified in your generators (e.g., formatting, additional code generation) - Reports results - Shows which clients were generated and where
Generator Configuration
Generators are configured in your BAML files (typicallygenerators.baml):
Output Types
Theoutput_type determines what language and format the client code will be generated in:
Python
TypeScript
Go
Ruby
Rust
OpenAPI
Examples
Basic generation
Generate all configured clients:Generate from a specific directory
Generate without version check
Useful during development when testing new CLI versions:Generate for production (no tests)
Reduce bundle size by excluding test definitions:Enable beta features
Show all warnings
Output
Successful generation shows what was created:Automatic Generation
If no generator configurations are found,baml generate will create a default client and suggest adding a generator configuration:
Post-Generation Hooks
Theon_generate field runs shell commands after generation. Common uses:
Format Python code
Format Go code
Format Rust code
Generate OpenAPI client
output_dir/baml_client directory.
Troubleshooting
Version mismatch error
Error: “Generator version 0.71.0 does not match CLI version 0.72.0” Solution: Update theversion field in your generators.baml to match your installed CLI version:
No BAML files found
Error: “Failed while searching for .baml files in baml_src/” Solution:- Ensure you’re in the right directory
- Check that
baml_src/exists and contains.bamlfiles - Use
--fromto specify the correct path:
Generator command fails
Error: “on_generate command failed” Solution: The post-generation hook returned an error. Common causes:- Formatting tool not installed (e.g.,
black,gofmt,openapi-generator) - Syntax errors in generated code
- Incorrect command in
on_generate
Import errors after generation
Issue: Generated client can’t be imported Solution:-
Ensure the BAML runtime library is installed:
- Check that the output directory is correct in your generator config
- For Python, ensure the output directory is in your Python path
Compilation errors in generated code
Issue: Generated code has syntax or type errors Solution:-
Validate your BAML syntax:
- Ensure you’re using matching versions of the CLI and runtime library
- Report the issue if it appears to be a bug in code generation
Integration with Development Workflow
Watch mode
For automatic regeneration during development, usebaml dev:
CI/CD Integration
Add generation to your build pipeline:Pre-commit Hook
Ensure generated code is up to date:Related Commands
baml init- Initialize a new BAML projectbaml dev- Development server with auto-regenerationbaml test- Run tests for your BAML functionsbaml serve- Start production HTTP API server