{"record":{"id":"8468b2d8a110f0aa","repo":"BoundaryML/baml","slug":"unknown-function","errorCode":null,"errorMessage":"Unknown function {}","messagePattern":"Unknown function (.+?)","errorType":"validation","errorClass":"DatamodelError","httpStatus":null,"severity":"error","filePath":"engine/baml-lib/baml-core/src/validate/validation_pipeline/validations/expr_fns.rs","lineNumber":301,"sourceCode":"    }\n}\n\nfn validate_expression(ctx: &mut Context<'_>, expr: &Expression, scope: &HashSet<String>) {\n    match &expr {\n        Expression::Identifier(identifier) => {\n            if !scope.contains(&identifier.to_string()) {\n                ctx.push_error(DatamodelError::new_anyhow_error(\n                    anyhow::anyhow!(\"Unknown variable {}\", &identifier.to_string()),\n                    identifier.span().clone(),\n                ));\n            }\n        }\n        Expression::Lambda(_args, _body, _span) => {}\n        Expression::App(app) => {\n            // Validate the function name.\n            if !scope.contains(app.name.name()) {\n                ctx.push_error(DatamodelError::new_anyhow_error(\n                    anyhow::anyhow!(\"Unknown function {}\", &app.name.to_string()),\n                    app.span().clone(),\n                ));\n            }\n\n            // Validate generics.\n            if ir::builtin::is_builtin_identifier(app.name.name()) && app.type_args.is_empty() {\n                ctx.push_error(DatamodelError::new_anyhow_error(\n                    anyhow::anyhow!(\n                        \"Generic function {} must have a type argument. Try adding a type argument like this: {}<Type>\",\n                        app.name.name(),\n                        app.name.name()\n                    ),\n                    app.span().clone(),\n                ));\n            }\n            for arg in &app.args {\n                validate_expression(ctx, arg, scope);\n            }","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-lib/baml-core/src/validate/validation_pipeline/validations/expr_fns.rs#L283-L319","documentation":"When validating an application expression (function call), the function name is looked up in the scope's set of known function identifiers. If the called name is not in scope, the validator pushes 'Unknown function {}'.","triggerScenarios":"Calling a function inside a BAML expression function where the callee name is not a defined expression function, builtin, or other in-scope callable.","commonSituations":"Typos in function names, calling a function that is defined but not visible/imported, invoking a helper that was renamed or deleted, calling a non-builtin before it is declared.","solutions":["Fix the function name spelling to match its definition","Define the function being called in the same baml_src scope","Use the correct builtin identifier if a builtin was intended","Check that the callee is declared before/in scope where used"],"exampleFix":"// before\nfunction main() {\n  return sumrize(text) // typo\n}\n// after\nfunction main() {\n  return summarize(text)\n}","handlingStrategy":"validation","validationCode":"// Confirm the callee is a known function before emitting the call\nlet known: HashSet<&str> = expr_fns.iter().map(|f| f.name.as_str()).collect();\nif !known.contains(callee_name) {\n    bail!(\"unknown function {}\", callee_name);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep function definitions in the same baml_src scope as callers","Use editor autocomplete to avoid name typos","Grep for the definition when renaming functions and update all call sites"],"tags":["baml","validation","function-call","undefined"],"backgroundTag":"entity-not-found","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"}