BoundaryML/baml · error

No tests found for function

Error message

No tests found for function '{}'

What it means

The optimizer's evaluator runs the tests defined in the BAML project against a specific function, filtered by the provided test_filter. If, after filtering, no tests remain for the function being evaluated, it bails with this error rather than 'successfully' doing nothing. This makes it obvious that a function name/test filter combination matched nothing in the project.

Solutions

  1. Check the function name for typos against `function` declarations in your .baml files
  2. Add one or more `test MyFunction { ... }` blocks for the function you're evaluating
  3. Relax or fix the test filter (name pattern / tags) so it matches the existing tests
  4. Run `baml-cli test --list` (or inspect the project) to see which functions actually have tests

Example fix

// before
baml-cli optimize eval --function ResumExtraction // typo

// after
baml-cli optimize eval --function ExtractResume

// and in baml_src
test ExtractResume {
  functions [ExtractResume]
  args { resume "..." }
}
Defensive patterns

Strategy: validation

Validate before calling

const definedFns = new Set([...src.matchAll(/^\s*function\s+(\w+)/gm)].map((m) => m[1]));
const testedFns = new Set([...src.matchAll(/test\s+\w+\s*\{\s*functions\s*\[([^\]]+)\]/g)].flatMap((m) => m[1].split(',').map((s) => s.trim())));
if (!testedFns.has('ExtractResume')) throw new Error('No tests target function ExtractResume');

Try / catch

try {
  await evaluator.evaluate('ExtractResume', filter);
} catch (e) {
  if (/No tests found for function/i.test(e.message)) {
    console.error('Add `test` blocks for this function or broaden the test filter');
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling evaluate (BamlEvaluator / `baml-cli optimize` evaluation) for a function_name whose `test` blocks either don't exist or are all excluded by the TestFilter (name pattern, tags, etc.).

Common situations: Typo in the function name passed to the evaluator/CLI; tests filtered out by tag or name-pattern filters; running optimization for a function that was renamed or deleted; a project where tests were removed but the optimize config still references them.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


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

Appendix: source

Thrown at engine/baml-runtime/src/optimize/evaluator.rs:148

    ) -> Result<(CandidateScores, Vec<TestEvalResult>)> {
        use crate::InternalRuntimeInterface;

        // Get tests for this function
        let ir = runtime.ir();
        let function = ir
            .walk_functions()
            .find(|f| f.name() == function_name)
            .with_context(|| format!("Function '{}' not found", function_name))?;

        let tests: Vec<_> = function
            .elem()
            .tests
            .iter()
            .filter(|t| test_filter.includes(function_name, &t.elem.name))
            .collect();

        if tests.is_empty() {
            anyhow::bail!("No tests found for function '{}'", function_name);
        }

        // Run tests
        let mut results = Vec::new();
        let semaphore = Arc::new(tokio::sync::Semaphore::new(self.parallel));

        let mut handles = Vec::new();

        for test_node in tests {
            let test_name = test_node.elem.name.clone();
            // Extract test inputs from the test definition
            let test_inputs: HashMap<String, String> = test_node
                .elem
                .args
                .iter()
                .map(|(k, v)| (k.clone(), format!("{:?}", v)))
                .collect();

View on GitHub (pinned to bd85ce9dee)