BoundaryML/baml · error · napi::Error
BamlError: Unexpected error from BAML: {err}
Error message
BamlError: Unexpected error from BAML: {err} What it means
from_anyhow_error downcasts an anyhow error to an LLMResponse; if it is LLMResponse::Success (a success value arriving on the error path, which should be impossible), BAML throws 'BamlError: Unexpected error from BAML: <err>' with GenericFailure. This indicates an internal invariant violation in error propagation.
Source
Thrown at engine/language_client_typescript/src/errors.rs:87
raw_response.as_deref(),
),
ExposedError::AbortError {
detailed_message, ..
} => throw_baml_abort_error(if detailed_message.is_empty() {
None
} else {
Some(detailed_message.as_str())
}),
ExposedError::TimeoutError {
client_name,
message,
} => throw_baml_timeout_error(client_name, message),
}
} else if let Some(er) = err.downcast_ref::<ScopeStack>() {
invalid_argument_error(&format!("{er}"))
} else if let Some(er) = err.downcast_ref::<LLMResponse>() {
match er {
LLMResponse::Success(_) => napi::Error::new(
napi::Status::GenericFailure,
format!("BamlError: Unexpected error from BAML: {err}"),
),
LLMResponse::LLMFailure(failed) => match &failed.code {
baml_runtime::internal::llm_client::ErrorCode::Other(2) => napi::Error::new(
napi::Status::GenericFailure,
format!(
"BamlError: BamlClientError: Something went wrong with the LLM client: {}",
failed.message
),
),
baml_runtime::internal::llm_client::ErrorCode::Timeout => {
throw_baml_timeout_error(failed.client.as_str(), failed.message.as_str())
}
baml_runtime::internal::llm_client::ErrorCode::Other(_)
| baml_runtime::internal::llm_client::ErrorCode::InvalidAuthentication
| baml_runtime::internal::llm_client::ErrorCode::NotSupported
| baml_runtime::internal::llm_client::ErrorCode::RateLimitedView on GitHub (pinned to bd85ce9dee)
Solutions
- Capture the full message and check for known issues at github.com/boundaryml/baml/issues.
- Upgrade @boundaryml/baml and the CLI to latest and regenerate — this class of bug is often fixed in newer releases.
- Reduce to a minimal .baml + client snippet and file a bug with the message text.
Defensive patterns
Strategy: try-catch
Try / catch
try {
const res = await b.MyFunction(input);
} catch (e) {
if (String(e.message).startsWith('BamlError: Unexpected error from BAML')) {
reportToBamlIssueTracker(e.message); // internal bug, not user-fixable
}
throw e;
} Prevention
- Keep CLI, runtime, and generated code on the same version to avoid state the error path mishandles.
- If reproducible, file a minimal repro at github.com/boundaryml/baml/issues.
When it happens
Trigger: An anyhow::Error wrapping LLMResponse::Success reaches from_anyhow_error during call_function/stream_function/etc.; i.e. the runtime converted a non-error response into the error channel.
Common situations: BAML runtime bugs; unusual client configurations confusing the result plumbing; typically reported upstream rather than fixed by user code.
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
- BamlError: BamlClientError: Something went wrong with the LL
- VM internal error: {0}
- {self}\n\nDetailed message: {detailed_message}
- Failed before LLM call: {message}
- Operation cancelled: {message}
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/42ec0082543aba83.
Report an issue: GitHub.