⚠️ IMPORTANT NOTEThis document was initially generated by an AI assistant and should be taken with a grain of salt. While it provides a good starting point, some information might be inaccurate or outdated. We encourage contributors to manually update this document and remove this note once the content has been verified and corrected by the team.
If you find any inaccuracies or have improvements to suggest, please feel free to submit a PR updating this guide.
BAML is designed as a modular system that transforms BAML source files into type-safe SDKs for multiple programming languages while providing runtime support for LLM interactions.
graph TD
A[BAML Source Files] --> B[Parser]
B --> C[AST]
C --> D[Type Checker]
D --> E[IR Generator]
E --> F[Code Generator]
F --> G[Python SDK]
F --> H[TypeScript SDK]
F --> I[Ruby SDK]
subgraph "Runtime"
J[LLM Client]
K[Type System]
L[Template Engine]
end
G --> J
H --> J
I --> J
J --> M[OpenAI]
J --> N[Anthropic]
J --> O[AWS Bedrock]
subgraph "Development Tools"
P[CLI]
Q[VSCode Extension]
R[Playground]
end
P --> B
Q --> B
R --> B
- Parser: Converts BAML source files into AST
- Type Checker: Validates types and relationships
- IR Generator: Creates intermediate representation
- Type definitions and validation
- Runtime value representation
- Schema compatibility checking
- Language-specific code generation
- Type mapping for each language
- SDK structure generation
- LLM provider integrations
- Request handling and validation
- Response processing
- Error management
- Native language bindings
- Type-safe interfaces
- Async/await support
- Error handling
- CLI for project management
- VSCode extension for development
- Web playground for testing
-
Compilation Phase
BAML Source → AST → IR → Generated Code
-
Runtime Phase
Client Call → Runtime → LLM Provider → Response → Type Validation → Result
-
Development Phase
Edit → Validate → Preview → Test → Generate
- Strong type system for LLM outputs
- Runtime validation of responses
- Language-specific type generation
- Separate compiler and runtime
- Pluggable LLM providers
- Language-agnostic core
- Rich error messages
- Interactive development tools
- Comprehensive testing support
- Efficient code generation
- Optimized runtime
- Smart caching
sequenceDiagram
participant S as Source Files
participant P as Parser
participant T as Type Checker
participant I as IR Generator
participant G as Code Generator
participant C as SDK Client
S->>P: BAML code
P->>T: AST
T->>I: Validated AST
I->>G: IR
G->>C: Generated code
sequenceDiagram
participant C as SDK Client
participant R as Runtime
participant L as LLM Provider
participant V as Validator
C->>R: Request
R->>L: LLM call
L->>R: Response
R->>V: Validate
V->>C: Result
The BAML compiler generates type-safe client libraries for multiple programming languages. For a detailed explanation of the code generation process, see our Code Generation Guide.
- Implement provider trait
- Add configuration options
- Create integration tests
- Create code generator
- Implement type mappings
- Add runtime bindings
- Extend type system
- Add compiler passes
- Create runtime middleware
- Incremental compilation
- Parallel code generation
- Smart caching
- Connection pooling
- Response streaming
- Efficient validation
- Fast feedback loop
- Intelligent caching
- Optimized previews
- Environment variables
- Secure configuration
- Key rotation support
- Input validation
- Output sanitization
- Error handling
- Safe defaults
- Security checks
- Audit logging
- More language support
- Additional LLM providers
- Enhanced type system
- Smarter caching
- Better parallelization
- Reduced memory usage
- Enhanced IDE support
- Better debugging tools
- More development features