BoundaryML/baml · error · anyhow::Error

Expr function error

Error message

Expr function error: {}

What it means

During WASM parsed_response_impl for a test run, the expression-function response could not be converted into a value: evaluating/serializing the expr function returned Err(e), which is re-wrapped as "Expr function error: {e}". This is the WASM/JS boundary reporting that the expr function's output was invalid.

Solutions

  1. Read the embedded {e} message for the expr function's actual failure
  2. Run the expr function logic standalone (baml-cli) to reproduce outside WASM
  3. Check argument types and null-handling in the expr function body
  4. Verify the BAML sources compile and all referenced functions exist
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-validate expr function inputs on the JS side
if (args.some((a) => a == null)) throw new Error('null argument passed to expr function');

Type guard

const isExprOk = (r) => r != null && r.kind === 'expr' && r.value !== undefined;

Try / catch

try {
  const parsed = await b.test.functionUnderTest(args);
} catch (e) {
  if (String(e).startsWith('Expr function error:')) {
    console.error('expr function body failed:', e.message);
  }
  throw e;
}

Prevention

When it happens

Trigger: parsed_response_impl called for a test whose function is an expr function; the internal expr-function value conversion returns Err, triggering the log::debug and the anyhow error.

Common situations: Expr functions that throw or return unexpected shapes when invoked from the browser/WASM test runner, e.g. division by zero, wrong argument types, or a dependent client failing.

Related errors


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

Appendix: source

Thrown at engine/baml-schema-wasm/src/runtime_wasm/mod.rs:817

                Ok(value)
            }
            _ => {
                // Try expr function response
                if let Some(expr_response) = &test_response.expr_function_response {
                    log::debug!(
                        "[BAML parsed_response_impl] Found expr_function_response: {:?}",
                        expr_response.as_ref().map(|v| format!("{v:?}"))
                    );
                    match expr_response {
                        Ok(value) => {
                            log::debug!(
                                "[BAML parsed_response_impl] Using expr function response value"
                            );
                            Ok(value)
                        }
                        Err(e) => {
                            log::debug!("[BAML parsed_response_impl] Expr function error: {e}");
                            Err(anyhow::anyhow!("Expr function error: {}", e))
                        }
                    }
                } else {
                    log::debug!(
                        "[BAML parsed_response_impl] No parsed value found in either response type"
                    );
                    Err(anyhow::anyhow!("No parsed value"))
                }
            }
        }
        .context("No parsed value")?;
        let (flattened_checks, check_count) = serialize_value_counting_checks(parsed_response);
        Ok(WasmParsedTestResponse {
            value: serde_json::to_string(&flattened_checks)?,
            check_count,
            explanation: {
                let j = parsed_response.explanation_json();
                if j.is_empty() {

View on GitHub (pinned to bd85ce9dee)