{"record":{"id":"42ec0082543aba83","repo":"BoundaryML/baml","slug":"bamlerror-unexpected-error-from-baml-err","errorCode":null,"errorMessage":"BamlError: Unexpected error from BAML: {err}","messagePattern":"BamlError: Unexpected error from BAML: (.+?)","errorType":"exception","errorClass":"napi::Error","httpStatus":null,"severity":"error","filePath":"engine/language_client_typescript/src/errors.rs","lineNumber":87,"sourceCode":"                raw_response.as_deref(),\n            ),\n            ExposedError::AbortError {\n                detailed_message, ..\n            } => throw_baml_abort_error(if detailed_message.is_empty() {\n                None\n            } else {\n                Some(detailed_message.as_str())\n            }),\n            ExposedError::TimeoutError {\n                client_name,\n                message,\n            } => throw_baml_timeout_error(client_name, message),\n        }\n    } else if let Some(er) = err.downcast_ref::<ScopeStack>() {\n        invalid_argument_error(&format!(\"{er}\"))\n    } else if let Some(er) = err.downcast_ref::<LLMResponse>() {\n        match er {\n            LLMResponse::Success(_) => napi::Error::new(\n                napi::Status::GenericFailure,\n                format!(\"BamlError: Unexpected error from BAML: {err}\"),\n            ),\n            LLMResponse::LLMFailure(failed) => match &failed.code {\n                baml_runtime::internal::llm_client::ErrorCode::Other(2) => napi::Error::new(\n                    napi::Status::GenericFailure,\n                    format!(\n                        \"BamlError: BamlClientError: Something went wrong with the LLM client: {}\",\n                        failed.message\n                    ),\n                ),\n                baml_runtime::internal::llm_client::ErrorCode::Timeout => {\n                    throw_baml_timeout_error(failed.client.as_str(), failed.message.as_str())\n                }\n                baml_runtime::internal::llm_client::ErrorCode::Other(_)\n                | baml_runtime::internal::llm_client::ErrorCode::InvalidAuthentication\n                | baml_runtime::internal::llm_client::ErrorCode::NotSupported\n                | baml_runtime::internal::llm_client::ErrorCode::RateLimited","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_typescript/src/errors.rs#L69-L105","documentation":"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.","triggerScenarios":"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.","commonSituations":"BAML runtime bugs; unusual client configurations confusing the result plumbing; typically reported upstream rather than fixed by user code.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const res = await b.MyFunction(input);\n} catch (e) {\n  if (String(e.message).startsWith('BamlError: Unexpected error from BAML')) {\n    reportToBamlIssueTracker(e.message); // internal bug, not user-fixable\n  }\n  throw e;\n}","preventionTips":["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."],"tags":["rust","napi","internal-error","llm"],"backgroundTag":"internal-invariant-violation","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}