{"record":{"id":"7cb7cfc5110b07e3","repo":"BoundaryML/baml","slug":"bamlerror-bamlinvalidargumenterror-msg","errorCode":null,"errorMessage":"BamlError: BamlInvalidArgumentError: {msg}","messagePattern":"BamlError: BamlInvalidArgumentError: (.+?)","errorType":"exception","errorClass":"napi::Error","httpStatus":null,"severity":"error","filePath":"engine/language_client_typescript/src/errors.rs","lineNumber":118,"sourceCode":"                    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\n                | baml_runtime::internal::llm_client::ErrorCode::ServerError\n                | baml_runtime::internal::llm_client::ErrorCode::ServiceUnavailable\n                | baml_runtime::internal::llm_client::ErrorCode::UnsupportedResponse(_) => {\n                    throw_baml_client_http_error(\n                        failed.client.as_str(),\n                        failed.message.as_str(),\n                        &failed.code,\n                        None,\n                        failed.raw_response.as_deref(),\n                    )\n                }\n            },\n            LLMResponse::UserFailure(msg) => napi::Error::new(\n                napi::Status::GenericFailure,\n                format!(\"BamlError: BamlInvalidArgumentError: {msg}\"),\n            ),\n            LLMResponse::InternalFailure(_) => napi::Error::new(\n                napi::Status::GenericFailure,\n                format!(\n                    \"BamlError: BamlClientError: Something went wrong with the LLM client: {err}\"\n                ),\n            ),\n            LLMResponse::Cancelled(msg) => napi::Error::new(\n                napi::Status::GenericFailure,\n                format!(\"BamlAbortError: Operation was aborted: {msg}\"),\n            ),\n        }\n    } else {\n        napi::Error::new(napi::Status::GenericFailure, format!(\"BamlError: {err:?}\"))\n    }\n}","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_typescript/src/errors.rs#L100-L136","documentation":"When from_anyhow_error sees LLMResponse::UserFailure(msg), BAML surfaces it as 'BamlError: BamlInvalidArgumentError: <msg>' with GenericFailure. UserFailure originates from user-supplied values failing checks (e.g. invalid media data, assertion failures on inputs) rather than the LLM provider.","triggerScenarios":"Constructing BamlImage/BamlPdf/BamlAudio with malformed or empty base64/URL data, or otherwise passing user input the runtime validates and rejects, on any call_function/stream_function path.","commonSituations":"Uploading truncated base64 media; passing a URL the runtime cannot treat as media; empty strings for required media content; mixing up fromUrl/fromBase64 inputs.","solutions":["Read the {msg} suffix — it describes the rejected value.","Validate media before calling: non-empty base64 that decodes, correct media type, reachable URL.","Use Baml's constructors (BamlImage.fromBase64/fromUrl, etc.) instead of hand-built objects."],"exampleFix":"// before\nconst img = await b.Describe(userInput); // userInput may be ''\n// after\nif (!userInput || userInput.trim() === '') throw new Error('image data required');\nconst img = await b.Describe(userInput);","handlingStrategy":"validation","validationCode":"function assertNonEmptyBase64(s: string) {\n  if (!s || s.length === 0) throw new Error('media base64 is empty');\n  Buffer.from(s, 'base64'); // throws on invalid base64\n}","typeGuard":"function isBamlUserFailure(e: unknown): e is Error {\n  return e instanceof Error && /^BamlError: BamlInvalidArgumentError:/.test(e.message);\n}","tryCatchPattern":"try {\n  const res = await b.DescribeImage(imageInput);\n} catch (e) {\n  if (isBamlUserFailure(e)) {\n    // message describes the rejected user input\n    return { ok: false, reason: e.message.replace('BamlError: BamlInvalidArgumentError: ', '') };\n  }\n  throw e;\n}","preventionTips":["Validate media content (non-empty, decodable base64, correct media type) before BAML calls.","Use BAML's typed constructors instead of ad-hoc objects.","Treat BamlInvalidArgumentError messages as user-input errors and surface them to callers."],"tags":["rust","napi","invalid-argument","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}