BoundaryML/baml · error
Typecheck errors
Error message
Typecheck errors: {errors} What it means
When constructing the async interpreter runtime, the BAML program is typechecked (HIR -> THIR). Any typecheck diagnostics marked as errors abort construction with this aggregate message containing the pretty-printed diagnostics.
Solutions
- Read the embedded diagnostics in the message and fix each type error in the .baml source.
- Run the BAML CLI typecheck on your project to see all errors before runtime.
- Check for type mismatches introduced by recent edits or generated code.
Example fix
// before (baml)
function F(x: int) -> string { ... }
F("hello")
// after (baml)
function F(x: int) -> string { ... }
F(42) Defensive patterns
Strategy: try-catch
Try / catch
match AsyncInterpreterRuntime::try_from(llm_runtime) {
Ok(rt) => rt,
Err(e) => {
eprintln!("BAML typecheck failed:\n{e:#}");
std::process::exit(1);
}
} Prevention
- Run `baml-cli fmt`/typecheck in CI before loading programs at runtime.
- Fix diagnostics top-down; later errors often cascade from earlier ones.
When it happens
Trigger: Calling AsyncInterpreterRuntime::try_from (e.g. via the BAML interactive/interpreter entry point) with a .baml source program that fails static typechecking.
Common situations: Passing wrong-typed arguments to functions in BAML code, incompatible return types, or referencing undefined types when programmatically loading BAML sources (playground, tests, interpreter).
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- array assignment index out of bounds
- array assignment on non-list value at
- array assignment requires a non-negative integer index at
- assign to undeclared variable
- baml.fetch_as expects 1 type argument, got
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/1526627e97010a7a.
Report an issue: GitHub.
Appendix: source
Thrown at engine/baml-runtime/src/async_interpreter_runtime.rs:79
}
impl TryFrom<LlmRuntime> for BamlAsyncInterpreterRuntime {
type Error = anyhow::Error;
fn try_from(llm_runtime: LlmRuntime) -> Result<Self, Self::Error> {
#[cfg(not(target_arch = "wasm32"))]
let async_runtime = Arc::clone(&llm_runtime.async_runtime);
// Stage 1: AST -> HIR
let hir_program = hir::Hir::from_ast(&llm_runtime.db.ast);
// Stage 2: HIR -> THIR (typecheck)
let mut diagnostics = Diagnostics::new("dummy".into());
let thir_program = typecheck(&hir_program, &mut diagnostics);
if diagnostics.has_errors() {
let errors = diagnostics.to_pretty_string();
return Err(anyhow::anyhow!("Typecheck errors: {errors}"));
}
Ok(Self {
llm_runtime: Arc::new(llm_runtime),
thir_program,
#[cfg(not(target_arch = "wasm32"))]
async_runtime,
})
}
}
impl BamlAsyncInterpreterRuntime {
pub fn internal(&self) -> &LlmRuntime {
&self.llm_runtime
}
pub fn disassemble(&self, function_name: &str) {View on GitHub (pinned to bd85ce9dee)