{"record":{"id":"55df4ff4c4f8323d","repo":"BoundaryML/baml","slug":"attempted-to-call-non-function","errorCode":null,"errorMessage":"attempted to call non-function","messagePattern":"attempted to call non-function","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":1815,"sourceCode":"                            return Ok(EvalValue::Value(value.clone()));\n                        } else {\n                            bail!(\"Environment variable '{}' not found\", key);\n                        }\n                    }\n                }\n\n                let callee = evaluate_expr(\n                    func,\n                    scopes,\n                    thir,\n                    run_llm_function,\n                    watch_handler,\n                    function_name,\n                )\n                .await?;\n                let (arity, body, meta) = match callee {\n                    EvalValue::Function(a, b, m) => (a, b, m),\n                    _ => bail!(\"attempted to call non-function\"),\n                };\n\n                // Check if this is an LLM function call\n                if let Some(Expr::Value(BamlValueWithMeta::String(marker, _))) = &body.trailing_expr\n                {\n                    if marker.starts_with(\"__LLM_FUNCTION__\") {\n                        let fn_name = marker.strip_prefix(\"__LLM_FUNCTION__\").unwrap().to_string();\n\n                        // Evaluate arguments and convert to BamlValue\n                        let mut llm_args: Vec<BamlValue> = Vec::with_capacity(args.len());\n                        for a in args.iter() {\n                            let arg_val = expect_value(\n                                evaluate_expr(\n                                    a,\n                                    scopes,\n                                    thir,\n                                    run_llm_function,\n                                    watch_handler,","sourceCodeStart":1797,"sourceCodeEnd":1833,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L1797-L1833","documentation":"After evaluating the callee of a call expression, the interpreter pattern-matches it as EvalValue::Function. If the evaluated callee is any other value (string, int, class instance, etc.) it throws \"attempted to call non-function\". The BAML code invoked something with call syntax `f(...)` that is not a function value.","triggerScenarios":"A call expression whose func expression evaluates to a non-function value — e.g. calling a variable holding a string/int, calling a class name instead of a method, or shadowing a function name with a value.","commonSituations":"Shadowing a function name with a local variable; calling a field that holds a value instead of a method; typo where the intended function was never defined and a same-named value resolved instead; interpreter evaluating dynamic/macro-generated BAML.","solutions":["Verify the identifier being called is actually a BAML function or fn definition, not a value","Rename any variable that shadows the function name you intend to call","If calling a method, ensure you access it via the correct base (e.g. obj.method()) rather than calling the object itself","Check for typos in the function name"],"exampleFix":"// before\nlet x = \"hello\"\nx() // attempted to call non-function\n// after\nfn greet() { \"hello\" }\ngreet()","handlingStrategy":"type-guard","validationCode":"// Confirm the callee resolves to a function before calling\nfunction assertCallable(fnName: string, knownFns: Set<string>): void {\n  if (!knownFns.has(fnName)) throw new Error(`${fnName} is not a defined BAML function`);\n}","typeGuard":"function isFunctionValue(v: unknown): v is (...args: unknown[]) => unknown {\n  return typeof v === \"function\";\n}","tryCatchPattern":"try {\n  return await callBamlFn(name, args);\n} catch (e) {\n  if (String(e).includes(\"attempted to call non-function\")) {\n    throw new Error(`'${name}' is not a function — check for shadowing or a typo`);\n  }\n  throw e;\n}","preventionTips":["Never reuse function names for variables in .baml files","Rely on the static checker/LSP to flag non-function call targets","Review call sites after converting a function to a value or vice versa","Search the .baml file for duplicate declarations of the same name"],"tags":["interpreter","type-mismatch","call"],"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"}