BoundaryML/baml · warning · BamlAbortError

BamlAbortError: Operation was aborted

Error message

BamlAbortError: Operation was aborted: {msg}

What it means

BamlAbortError indicates the LLM call was cancelled: from_anyhow_error maps LLMResponse::Cancelled to this message. It signals the request was aborted (by the caller or the runtime) rather than failing at the provider.

Solutions

  1. Check whether your own code (AbortController, request cancellation) triggered the abort
  2. If the abort is unexpected, review timeout/shutdown handling around the BAML call
  3. Re-run the request; aborted calls are safe to retry
  4. If aborts are legitimate, catch BamlAbortError and treat it as a user-initiated cancellation

Example fix

// before
const result = await b.MyFunction(args); // caller abort propagates as thrown error
// after
try {
  const result = await b.MyFunction(args);
} catch (e) {
  if (String(e).startsWith('BamlAbortError')) return null; // treat as cancellation
  throw e;
}
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure the AbortSignal is still alive before the call
if (signal?.aborted) return null;

Type guard

const isAbortError = (e: unknown): boolean => String(e).startsWith('BamlAbortError');

Try / catch

try {
  const result = await b.MyFunction(args, { abortSignal });
} catch (e) {
  if (isAbortError(e)) return null; // user cancellation, not a failure
  throw e;
}

Prevention

When it happens

Trigger: Aborting an in-flight generated-function call (AbortSignal / cancellation token), dropping the awaiting task, or the runtime cancelling the request so the driver returns LLMResponse::Cancelled.

Common situations: Users cancel a request in the UI and the app propagates the abort; request timeouts implemented via AbortController; server shutdown mid-call.

Understand the failure class

Background: Request timed out: what client-side request timeouts mean across libraries (Request timed out, TIMED_OUT, APITimeoutError) — this error's family across 39 libraries.

Related errors


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

Appendix: source

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

                        failed.client.as_str(),
                        failed.message.as_str(),
                        &failed.code,
                        None,
                        failed.raw_response.as_deref(),
                    )
                }
            },
            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,

View on GitHub (pinned to bd85ce9dee)