{"record":{"id":"1526627e97010a7a","repo":"BoundaryML/baml","slug":"typecheck-errors-errors","errorCode":null,"errorMessage":"Typecheck errors: {errors}","messagePattern":"Typecheck errors: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/async_interpreter_runtime.rs","lineNumber":79,"sourceCode":"}\n\nimpl TryFrom<LlmRuntime> for BamlAsyncInterpreterRuntime {\n    type Error = anyhow::Error;\n\n    fn try_from(llm_runtime: LlmRuntime) -> Result<Self, Self::Error> {\n        #[cfg(not(target_arch = \"wasm32\"))]\n        let async_runtime = Arc::clone(&llm_runtime.async_runtime);\n\n        // Stage 1: AST -> HIR\n        let hir_program = hir::Hir::from_ast(&llm_runtime.db.ast);\n\n        // Stage 2: HIR -> THIR (typecheck)\n        let mut diagnostics = Diagnostics::new(\"dummy\".into());\n        let thir_program = typecheck(&hir_program, &mut diagnostics);\n\n        if diagnostics.has_errors() {\n            let errors = diagnostics.to_pretty_string();\n            return Err(anyhow::anyhow!(\"Typecheck errors: {errors}\"));\n        }\n\n        Ok(Self {\n            llm_runtime: Arc::new(llm_runtime),\n            thir_program,\n\n            #[cfg(not(target_arch = \"wasm32\"))]\n            async_runtime,\n        })\n    }\n}\n\nimpl BamlAsyncInterpreterRuntime {\n    pub fn internal(&self) -> &LlmRuntime {\n        &self.llm_runtime\n    }\n\n    pub fn disassemble(&self, function_name: &str) {","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/async_interpreter_runtime.rs#L61-L97","documentation":"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.","triggerScenarios":"Calling AsyncInterpreterRuntime::try_from (e.g. via the BAML interactive/interpreter entry point) with a .baml source program that fails static typechecking.","commonSituations":"Passing wrong-typed arguments to functions in BAML code, incompatible return types, or referencing undefined types when programmatically loading BAML sources (playground, tests, interpreter).","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."],"exampleFix":"// before (baml)\nfunction F(x: int) -> string { ... }\nF(\"hello\")\n// after (baml)\nfunction F(x: int) -> string { ... }\nF(42)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match AsyncInterpreterRuntime::try_from(llm_runtime) {\n    Ok(rt) => rt,\n    Err(e) => {\n        eprintln!(\"BAML typecheck failed:\\n{e:#}\");\n        std::process::exit(1);\n    }\n}","preventionTips":["Run `baml-cli fmt`/typecheck in CI before loading programs at runtime.","Fix diagnostics top-down; later errors often cascade from earlier ones."],"tags":["typecheck","interpreter","baml","static-analysis"],"backgroundTag":"type-mismatch","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}