A recording and playback system for BAML function calls, inspired by the VCR pattern in testing. BAML VCR allows you to capture LLM interactions during test runs and replay them without making actual API calls, making your tests faster, more reliable, and cost-effective.
Source: https://github.com/BoundaryML/baml/tree/canary
- Record & Replay: Capture BAML function calls and their responses, then replay them in subsequent test runs
- Streaming Support: Full support for streaming BAML functions with chunk-by-chunk recording
- Multiple Recording Modes: Choose between "once", "new_episodes", "none", or "all" recording strategies
- Async Support: Works with both synchronous and asynchronous BAML functions
- YAML Storage: Human-readable cassette files stored in YAML format
- Automatic Test Discovery: Cassettes are automatically named based on test class and method names
- Type Preservation: Preserves complex BAML response types during serialization
BAML VCR is not yet available on PyPI. To install, clone the repository and install from source:
Or install directly from GitHub:
- Records interactions if cassette doesn't exist
- Replays from cassette if it exists
- Perfect for standard test scenarios
- Replays existing interactions
- Records any new, unmatched calls
- Useful when adding new test cases
- Only replays, never records
- Raises error if interaction not found
- Use in CI/CD pipelines
- Always records, overwrites existing cassette
- Useful for refreshing test data
Cassettes are stored in baml_cassettes/ directory next to your test files:
- Interception: BAML VCR patches BAML client functions at runtime
- Recording: When recording is enabled, it uses BAML's Collector to capture function calls and responses
- Storage: Interactions are serialized to YAML, preserving type information
- Playback: On replay, responses are returned from the cassette without making API calls
- Streaming: For streaming functions, individual chunks are recorded and replayed with realistic timing
- Commit Cassettes: Include cassette files in version control for consistent test behavior
- Refresh Periodically: Use record_mode="all" occasionally to update test data
- Separate Test Data: Use different cassettes for different test scenarios
- Review Changes: Check cassette diffs when updating to ensure expected behavior
- CI/CD: Use record_mode="none" in CI to ensure deterministic tests
If you see "No recorded response found", either:
- Delete the cassette to re-record
- Change record_mode to "once" or "all"
- Check that the function arguments match exactly
Streaming cassettes are saved with .streaming.cassette.yaml extension. Ensure you're not mixing streaming and non-streaming calls in the same test.
BAML VCR preserves type information during serialization. If you encounter type errors, check that your BAML client version matches between recording and playback.
Contributions are welcome! Please feel free to submit a Pull Request. If it does not break existing functionality, I will merge it.
MIT License - see LICENSE file for details
.png)


![Shell companies and government corruption [pdf]](https://news.najib.digital/site/assets/img/broken.gif)