BoundaryML/baml · error · RuntimeCallbackError
Type error in JS callback: {0}
Error message
Type error in JS callback: {0} What it means
RuntimeCallbackError::JsCallbackTypeError is raised when the value returned from the JS credential callback cannot be correctly shaped/typed when crossing the WASM bridge - i.e. the JS side returned something that does not deserialize into the expected credential result envelope (JsCallbackResult<T>). It is a data-shape mismatch between the JS provider's return value and the Rust expected type, not a thrown JS exception.
Source
Thrown at engine/baml-runtime/src/types/js_callback_provider.rs:32
#[derive(Debug, serde::Deserialize, Eq, PartialEq)]
/// Deserialization helper for js_callback_bridge; declared here to enable deserialization unit testing.
pub struct JsCallbackError {
pub name: String,
pub message: String,
}
#[derive(Debug, Error, Clone)]
/// For baml-src-reader and aws-cred-provider, provide a statically defined type which is Send + Sync
/// anyhow::Error is not Send + Sync, so it's convoluted to use it in this callback context
pub enum RuntimeCallbackError {
#[error("Failed to send cred request across WASM bridge: {0}")]
SendError(String),
#[error("Failed to recv cred response across WASM bridge: {0}")]
RecvError(String),
#[error("Type error in JS callback: {0}")]
JsCallbackTypeError(String),
#[error("JS callback error: {name}: {message}")]
JsCallbackRuntimeError { name: String, message: String },
#[error("BAML internal error - credential provider bridges not initialized")]
NoCredProviderBridge,
}
static_assertions::assert_impl_all!(RuntimeCallbackError: Send, Sync);
pub type RuntimeCallbackResult<T> = Result<T, RuntimeCallbackError>;
static JS_CALLBACK_PROVIDER_SINGLETON: OnceLock<JsCallbackProvider> = OnceLock::new();
pub fn get_js_callback_provider() -> Result<&'static JsCallbackProvider, RuntimeCallbackError> {
JS_CALLBACK_PROVIDER_SINGLETON
.get()View on GitHub (pinned to bd85ce9dee)
Solutions
- Make the JS credential callback return an object matching AwsCredentialIdentity (`accessKeyId`, `secretAccessKey`, optional `sessionToken`) or the documented ok/error envelope.
- Log the raw value returned by your JS provider and compare it field-by-field with the expected camelCase schema.
- Check that your provider resolves with the credential object rather than returning undefined (e.g. an async function without a return).
- If wrapping the Smithy provider, verify the SDK version's AwsCredentialIdentity shape matches what BAML's bridge expects.
Example fix
// before: wrong field names in JS provider return
async () => ({ accessKey: 'AKIA...', secret: '...' });
// after: match the expected AwsCredentialIdentity shape
async () => ({ accessKeyId: 'AKIA...', secretAccessKey: '...', sessionToken: undefined }); Defensive patterns
Strategy: validation
Validate before calling
// validate the JS provider's return shape before registering it
function isValidAwsCred(c) {
return c && typeof c.accessKeyId === 'string' && typeof c.secretAccessKey === 'string';
}
const provider = async (args) => {
const cred = await myProvider(args);
if (!isValidAwsCred(cred)) throw new Error('Provider returned invalid credential shape');
return cred;
}; Type guard
function isAwsCredentialIdentity(v) {
return (
typeof v === 'object' && v !== null &&
typeof v.accessKeyId === 'string' &&
typeof v.secretAccessKey === 'string' &&
(v.sessionToken === undefined || typeof v.sessionToken === 'string')
);
} Prevention
- Return camelCase fields exactly matching AwsCredentialIdentity (accessKeyId, secretAccessKey)
- Always resolve the provider promise with a credential object, never undefined
- Unit-test your JS provider's return value against the expected shape
When it happens
Trigger: The JS/WASM bridge deserializes the callback response via JsCallbackResult<T>/serde (js_callback_provider.rs:8-20) and the returned object fails type checking - e.g. missing `ok`/`error` envelope keys, wrong field names, or wrong primitive types - producing a type error surfaced as `JsCallbackTypeError(String)`.
Common situations: A custom JS AWS credential provider returns credentials with misspelled camelCase fields (e.g. `accessKey` instead of `accessKeyId`), returns a raw credential object instead of the expected envelope, or returns undefined/null when the provider fails silently.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- JS callback error: {name}: {message}
- baml.json.serialize returned non-string value: {other:?}
- Failed to resolve {}
- JavaScript error: {0:?}
- BAML internal error - credential provider bridges not initia
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/440b60c9ebeb2218.
Report an issue: GitHub.