BoundaryML/baml · error
Type error: {}
Error message
Type error: {} What it means
The BAML REPL type-checks each typed expression before evaluation; if the compiler's type diagnostics contain errors, evaluation is aborted and all type-error messages are joined into one anyhow error. This guarantees expressions only run once they pass type inference.
Source
Thrown at engine/baml-runtime/src/cli/repl.rs:514
if type_diagnostics.has_errors() {
eprintln!("Warning: Type errors in loaded BAML sources");
}
let input_expr_ast = parse_standalone_expression(input, &mut type_diagnostics)?;
let input_expr_hir = hir::Expression::from_ast(&input_expr_ast);
let input_expr_thir =
typecheck_expression(&input_expr_hir, &type_context, &mut type_diagnostics);
// Check for type errors in the user's expression
if type_diagnostics.has_errors() {
let error_messages: Vec<String> = type_diagnostics
.errors()
.iter()
.map(|e| e.message().to_string())
.collect();
return Err(anyhow!("Type error: {}", error_messages.join("; ")));
}
// let variables: IndexMap<String, BamlValueWithMeta<TypeGeneric<TypeIR>>> = self
let variables: IndexMap<String, BamlValueWithMeta<ExprMetadata>> = self
.variables
.iter()
.map(|(k, v)| (k.clone(), v.clone()))
.collect();
let fn_params = self.function_parameters()?.clone();
let runtime_clone = self.runtime.clone();
let env_vars = self.env_vars.clone();
let run_id = self.current_run_id.unwrap_or(0);
let handle_llm_function = move |function_name: String,
args: Vec<BamlValue>,
_watch_context: Option<View on GitHub (pinned to bd85ce9dee)
Solutions
- Fix the reported type error in the expression (read the joined messages after 'Type error:')
- Run :type <expression> first to check the inferred type before evaluating
- Use explicit casts or correct literal types in the expression
- Re-check variable types with :env after reloading BAML sources
Example fix
// before (REPL input)
MyFn("hello") // where MyFn expects int
// after
MyFn(42) Defensive patterns
Strategy: validation
Validate before calling
// Before evaluating, type-check the expression at the REPL
:type MyFn(arg1, arg2)
// In embedding code: match on the Result and inspect the anyhow message
if let Err(e) = repl.parse_and_evaluate_baml_expression(expr) {
if e.to_string().starts_with("Type error:") { /* show diagnostics to user */ }
} Try / catch
match result { Err(e) if e.to_string().starts_with("Type error:") => println!("Fix types: {e}"), Ok(v) => println!("{v:?}"), Err(e) => eprintln!("{e:#}") } Prevention
- Run :type on expressions before evaluating them
- Keep variable types visible with :env after each reload
- Match literal types to function signatures (int vs string vs float)
- After :load, re-verify calls whose signatures changed
When it happens
Trigger: Calling parse_and_evaluate_baml_expression_with_status (directly or via evaluate_simple_expression_with_status / parse_and_evaluate_baml_expression) with an expression whose BAML type checking fails, e.g. passing a string to a function expecting an int.
Common situations: Typing an expression with a type mismatch at the REPL prompt, calling an LLM function with wrongly-typed positional arguments, using a variable of the wrong type after :load reloads sources with changed signatures.
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
- No BAML sources loaded. Use :load <path> to load sources.
- LLM Function {} not found
- Failed to parse function result: {}
- No parsed result available from function call
- No runtime loaded, it should be impossible to call an LLM fu
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/6a44cc08d7e28f97.
Report an issue: GitHub.