{"record":{"id":"b3c0104e0523b63b","repo":"BoundaryML/baml","slug":"function-target-name-not-found","errorCode":null,"errorMessage":"function `{target_name}` not found","messagePattern":"function `(.+?)` not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_exec/src/dispatch.rs","lineNumber":96,"sourceCode":"\n/// Invoke a target with a caller-provided function context.\n///\n/// The callback runs after the target call completes and again after any output\n/// conversion hook, immediately before its return value is written. CLI callers\n/// use these boundaries to flush captured `log.*` events without changing the\n/// default dispatch behavior used by packaged binaries.\npub async fn dispatch_target_with_context(\n    engine: Arc<BexEngine>,\n    target_name: &str,\n    cli_values: HashMap<String, BexExternalValue>,\n    json_args: Option<serde_json::Value>,\n    output_format: OutputFormat,\n    call_context: FunctionCallContext,\n    after_call: impl Fn(),\n) -> Result<DispatchResult> {\n    let func_info = engine\n        .find_user_function(target_name)\n        .ok_or_else(|| anyhow!(\"function `{target_name}` not found\"))?;\n\n    // BEP-027 §\"Auto-CLI conventions\": `help` is reserved at entry-point\n    // resolution under both `baml run` and `baml pack`. Pack catches this\n    // at pack time; checking again here covers the run side and is a\n    // belt-and-suspenders against future host callers. Pass the canonical\n    // post-resolved name so the validator sees the same identifier that\n    // `find_user_function` matched, not the raw user input.\n    validate_help_param(&engine, &func_info.qualified_name)?;\n\n    let helper_context = HelperCallContext::from_call_context(&call_context);\n    let args = build_args_from_signature_with_context(\n        &engine,\n        cli_values,\n        json_args.as_ref(),\n        &func_info.param_names,\n        &func_info.param_types,\n        &func_info.param_has_default,\n        &helper_context,","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_exec/src/dispatch.rs#L78-L114","documentation":"`dispatch_target_with_context` resolves the target through `engine.find_user_function`; if the name doesn't match any user-defined function, dispatch aborts with this error before any CLI validation or execution.","triggerScenarios":"Running `baml run <name>` (or `baml pack` dispatch) where `<name>` doesn't resolve to a user function in the loaded engine - misspelled name, function not exported/visible, or the defining file not loaded into the project.","commonSituations":"Typos in the target name, invoking a generated/internal function rather than a user function, or the defining .baml file failing to load so the function never registers.","solutions":["Run `baml run --help` or list available functions to see valid target names and fix the spelling.","Ensure the .baml file defining the function is in the project and loads without errors.","Check for visibility/export issues - generators or internal helpers are not dispatchable user functions."],"exampleFix":"// before\nbaml run myFunc  // error: function `myFunc` not found\n\n// after\nbaml run my_function  // matches the actual declared name","handlingStrategy":"validation","validationCode":"let available = list_user_functions(&engine)?;\nif !available.contains(&target_name) {\n    anyhow::bail!(\"unknown target `{target_name}`; available: {available:?}\");\n}","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"not found\") => {\n        eprintln!(\"check the function name; run `baml run --help` to list targets\");\n    }\n    other => other,\n}","preventionTips":["Copy target names from --help output rather than typing them","Ensure the defining .baml file loads cleanly before dispatch","Don't dispatch generated/internal functions; only user functions are valid targets"],"tags":["cli","not-found","baml"],"backgroundTag":"command-not-found","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}