{"record":{"id":"c88f9366eeec3abe","repo":"BoundaryML/baml","slug":"bamlerror-bamlinvalidargumenterror-message","errorCode":null,"errorMessage":"BamlError: BamlInvalidArgumentError: {message}","messagePattern":"BamlError: BamlInvalidArgumentError: (.+?)","errorType":"exception","errorClass":"napi::Error","httpStatus":null,"severity":"error","filePath":"engine/language_client_typescript/src/errors.rs","lineNumber":10,"sourceCode":"use baml_runtime::{\n    errors::ExposedError,\n    internal::llm_client::{ErrorCode, LLMResponse},\n    scope_diagnostics::ScopeStack,\n};\n\n// napi::Error::new(napi::Status::GenericFailure, e.to_string()))\n\npub fn invalid_argument_error(message: &str) -> napi::Error {\n    napi::Error::new(\n        napi::Status::InvalidArg,\n        format!(\"BamlError: BamlInvalidArgumentError: {message}\"),\n    )\n}\n\n// Creating custom errors in JS is still not supported https://github.com/napi-rs/napi-rs/issues/1205\npub fn from_anyhow_error(err: anyhow::Error) -> napi::Error {\n    if let Some(er) = err.downcast_ref::<ExposedError>() {\n        match er {\n            ExposedError::ValidationError {\n                prompt,\n                message,\n                raw_output: raw_response,\n                detailed_message,\n                ..\n            } => throw_baml_validation_error(\n                prompt,\n                raw_response,","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_typescript/src/errors.rs#L1-L28","documentation":"invalid_argument_error builds a napi::Error with napi::Status::InvalidArg wrapping 'BamlError: BamlInvalidArgumentError: <message>'. Since custom JS error classes are not yet supported by napi-rs, BAML encodes its error taxonomy in the message string, surfaced to JS as a generic Error.","triggerScenarios":"Any Rust-side validation failing an argument before/at runtime call: malformed client registry, bad function/argument names, invalid enum or media values passed into call_function, stream_function, build_request, or from_anyhow_error downcasting ScopeStack errors.","commonSituations":"Calling b.MyFunction with wrong argument types from JS/TS; referencing a function/client that doesn't exist in the .baml files; passing malformed Image/Audio/Pdf content; generated client out of sync with .baml definitions.","solutions":["Read the {message} suffix — it names the invalid argument/expected type.","Regenerate the client (`baml generate`) so TS signatures match the .baml files.","Check argument types/values against the function signature (strings vs enums, media objects via BamlImage/BamlAudio/BamlPdf)."],"exampleFix":"// before\nconst res = await b.ExtractInfo(input.pdf);\n// after\nconst res = await b.ExtractInfo(BamlPdf.fromBase64(input.pdfBase64, 'application/pdf'));","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isBamlInvalidArgument(e: unknown): e is Error {\n  return e instanceof Error && e.message.startsWith('BamlError: BamlInvalidArgumentError:');\n}","tryCatchPattern":"try {\n  const res = await b.MyFunction(input);\n} catch (e) {\n  if (isBamlInvalidArgument(e)) {\n    // e.message after the prefix describes the bad argument\n    throw new TypeError(e.message.replace('BamlError: BamlInvalidArgumentError: ', ''));\n  }\n  throw e;\n}","preventionTips":["Use the generated TS client signatures so argument types are checked at compile time.","Regenerate the client after editing .baml files.","Build media inputs with BamlImage/BamlPdf/BamlAudio constructors only."],"tags":["rust","napi","invalid-argument","typescript"],"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-14T05:17:10.506Z"}