test
Tests are first-class citizens in BAML, designed to make testing AI functions straightforward and robust. BAML tests can be written anywhere in your codebase and run with minimal setup.
Overview
A BAML test consists of:
- Test name and metadata
- Functions under test
- Input arguments
- Optional testing configuration
- Optional assertions
- Optional type builders
Test Declaration
Basic Syntax
Optional Features
Components
name
: Test identifier (unique per function)functions
: List of functions to testargs
: Input parameters for the test casetype_builder
: Block used to inject values into dynamic types@@check
: Conditional check for test validity@@assert
: Assertion for test result
Input Types
Basic Types
Simple values are provided directly:
Complex Objects
Objects are specified using nested structures:
Arrays
Arrays use bracket notation:
Media Inputs
Images
Images can be specified using three methods:
- File Reference
- URL Reference
- Base64 Data
Audio
Similar to images, audio can be specified in three ways:
- File Reference
- URL Reference
- Base64 Data
Multi-line Strings
For long text inputs, use the block string syntax:
Testing Multiple Functions
This requires each function to have the exact same parameters:
Testing Dynamic Types
Dynamic types can be tested using type_builder
and dynamic
blocks:
Integration with Development Tools
VSCode Integration
- Tests can be run directly from the BAML playground
- Real-time syntax validation
- Test result visualization