BoundaryML/baml · error
Test '{}' not found for expr function '{}'
Error message
Test '{}' not found for expr function '{}' What it means
This error is thrown by get_test_type_builder_impl when a named test cannot be located for an expr-function in the BAML IR. The runtime looked up the expr function via find_expr_fn, then searched its attached tests with find_test(test_name) and got None, so it reports which test name and which function name were requested. It exists to surface typos/stale test references in the baml_src test definitions rather than silently returning no type builder.
Source
Thrown at engine/baml-runtime/src/lib.rs:880
let type_builder = TypeBuilder::new();
type_builder.add_entries(test.type_builder_contents());
type_builder
.recursive_type_aliases()
.lock()
.unwrap()
.extend(test.type_builder_recursive_aliases().iter().cloned());
type_builder
.recursive_classes()
.lock()
.unwrap()
.extend(test.type_builder_recursive_classes().iter().cloned());
return Ok(Some(type_builder));
}
let expr_fn = self.ir().find_expr_fn(function_name)?;
let test = expr_fn.find_test(test_name).ok_or_else(|| {
anyhow::anyhow!(
"Test '{}' not found for expr function '{}'",
test_name,
function_name
)
})?;
if test.item.1.elem.type_builder.entries.is_empty() {
return Ok(None);
}
let type_builder = TypeBuilder::new();
type_builder.add_entries(&test.item.1.elem.type_builder.entries);
type_builder
.recursive_type_aliases()
.lock()
.unwrap()
.extend(
test.itemView on GitHub (pinned to bd85ce9dee)
Solutions
- Check the test name spelling and that it is declared inside the specified expr function in your .baml files
- Regenerate/refresh the BAML runtime IR (rebuild or re-run baml-cli generate) after editing baml_src
- List the existing tests for the expr function and run one of those instead
- If the test lives on another function, pass the correct function_name to the call
Example fix
// before
let tb = runtime.get_test_type_builder("MyFunction", "my_test", &ctx).await?;
// after
// baml_src now defines `test my_test { ... }` inside MyFunction,
// or the call uses the correct function name:
let tb = runtime.get_test_type_builder("MyFunction", "correct_test_name", &ctx).await?; Defensive patterns
Strategy: validation
Validate before calling
// Rust: verify the test exists before requesting its type builder
let expr_fn = runtime.ir().find_expr_fn(function_name)?;
if expr_fn.find_test(test_name).is_none() {
return Err(anyhow!("test '{test_name}' not defined for '{function_name}'"));
} Prevention
- Keep test names in a single source of truth and reference them by constant/enum in harnesses
- Regenerate IR after every edit to baml_src before running tests
- List available tests programmatically instead of hardcoding names
When it happens
Trigger: Calling get_test_type_builder (or run_test_with_expr_events, which calls it) with a test_name that is not defined under the expr function named function_name in the compiled BAML sources.
Common situations: Typo in the test name passed to the CLI or test runner; the test was renamed or deleted from the .baml file while an old harness still references it; running a test defined on a different function than the one given; partially generated/stale IR after editing baml_src.
Understand the failure class
Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.
Related errors
- run_filtered failed: {e}
- {0}
- interned member `{name}` cannot be another member's child
- the master member cannot be interned: the master is the plai
- {message}
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/a363360358da5803.
Report an issue: GitHub.