BoundaryML/baml · error

function `{target_name}` not found

Error message

function `{target_name}` not found

What it means

`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.

Source

Thrown at baml_language/crates/baml_exec/src/dispatch.rs:96

/// Invoke a target with a caller-provided function context.
///
/// The callback runs after the target call completes and again after any output
/// conversion hook, immediately before its return value is written. CLI callers
/// use these boundaries to flush captured `log.*` events without changing the
/// default dispatch behavior used by packaged binaries.
pub async fn dispatch_target_with_context(
    engine: Arc<BexEngine>,
    target_name: &str,
    cli_values: HashMap<String, BexExternalValue>,
    json_args: Option<serde_json::Value>,
    output_format: OutputFormat,
    call_context: FunctionCallContext,
    after_call: impl Fn(),
) -> Result<DispatchResult> {
    let func_info = engine
        .find_user_function(target_name)
        .ok_or_else(|| anyhow!("function `{target_name}` not found"))?;

    // BEP-027 §"Auto-CLI conventions": `help` is reserved at entry-point
    // resolution under both `baml run` and `baml pack`. Pack catches this
    // at pack time; checking again here covers the run side and is a
    // belt-and-suspenders against future host callers. Pass the canonical
    // post-resolved name so the validator sees the same identifier that
    // `find_user_function` matched, not the raw user input.
    validate_help_param(&engine, &func_info.qualified_name)?;

    let helper_context = HelperCallContext::from_call_context(&call_context);
    let args = build_args_from_signature_with_context(
        &engine,
        cli_values,
        json_args.as_ref(),
        &func_info.param_names,
        &func_info.param_types,
        &func_info.param_has_default,
        &helper_context,

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Run `baml run --help` or list available functions to see valid target names and fix the spelling.
  2. Ensure the .baml file defining the function is in the project and loads without errors.
  3. Check for visibility/export issues - generators or internal helpers are not dispatchable user functions.

Example fix

// before
baml run myFunc  // error: function `myFunc` not found

// after
baml run my_function  // matches the actual declared name
Defensive patterns

Strategy: validation

Validate before calling

let available = list_user_functions(&engine)?;
if !available.contains(&target_name) {
    anyhow::bail!("unknown target `{target_name}`; available: {available:?}");
}

Try / catch

match result {
    Err(e) if e.to_string().contains("not found") => {
        eprintln!("check the function name; run `baml run --help` to list targets");
    }
    other => other,
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/b3c0104e0523b63b. Report an issue: GitHub.