BoundaryML/baml · error · napi::Error

BamlError: {err:?}

Error message

BamlError: {err:?}

What it means

This is the fallback branch of from_anyhow_error: when the error chain cannot be classified into an LLM response variant, BAML formats the raw anyhow error with {err:?} under a generic BamlError prefix. It means an unstructured internal error escaped the typed error plumbing.

Source

Thrown at engine/language_client_typescript/src/errors.rs:134

                }
            },
            LLMResponse::UserFailure(msg) => napi::Error::new(
                napi::Status::GenericFailure,
                format!("BamlError: BamlInvalidArgumentError: {msg}"),
            ),
            LLMResponse::InternalFailure(_) => napi::Error::new(
                napi::Status::GenericFailure,
                format!(
                    "BamlError: BamlClientError: Something went wrong with the LLM client: {err}"
                ),
            ),
            LLMResponse::Cancelled(msg) => napi::Error::new(
                napi::Status::GenericFailure,
                format!("BamlAbortError: Operation was aborted: {msg}"),
            ),
        }
    } else {
        napi::Error::new(napi::Status::GenericFailure, format!("BamlError: {err:?}"))
    }
}

fn throw_baml_validation_error(
    prompt: &str,
    raw_output: &str,
    message: &str,
    detailed_message: Option<&str>,
) -> napi::Error {
    let error_json = serde_json::json!({
        "type": "BamlValidationError",
        "prompt": prompt,
        "raw_output": raw_output,
        "message": format!("BamlValidationError: {}", message),
        "detailed_message": detailed_message,
    });
    napi::Error::new(napi::Status::GenericFailure, error_json.to_string())
}

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Read the Debug-formatted {err:?} payload for the root cause
  2. Check baml_src configuration and that the runtime context is initialized correctly
  3. Reproduce with BAML_DEBUG/verbose logging enabled to capture the full error chain
  4. File a bug with the full error if it persists — this branch indicates an unclassified error
Defensive patterns

Strategy: try-catch

Validate before calling

// sanity-check runtime context is initialized
if (!ctxManager || typeof ctxManager.getContext !== 'function') throw new Error('BAML runtime context not initialized');

Type guard

const isGenericBamlError = (e: unknown): boolean => typeof e === 'string' && e.startsWith('BamlError:') && !e.includes('BamlClientError');

Try / catch

try {
  const result = await b.MyFunction(args);
} catch (e) {
  const msg = typeof e === 'string' ? e : String(e);
  if (msg.startsWith('BamlError:')) {
    console.error('Unclassified BAML error:', msg);
    throw new Error('BAML internal failure: ' + msg);
  }
  throw e;
}

Prevention

When it happens

Trigger: Any unclassified anyhow error bubbling out of the runtime into the NAPI boundary — runtime startup failures, internal panics converted to errors, misconfigured context, or bugs in error classification.

Common situations: Running with an incompatible runtime context manager, corrupt BAML config loaded at runtime, or internal invariant violations that never reached the LLM.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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