{"record":{"id":"4bdb9c4f1fd6c4c8","repo":"BoundaryML/baml","slug":"type-mismatch-message","errorCode":null,"errorMessage":"Type mismatch: {message}","messagePattern":"Type mismatch: (.+?)","errorType":"exception","errorClass":"EngineError","httpStatus":null,"severity":"error","filePath":"baml_language/crates/bex_engine/src/lib.rs","lineNumber":845,"sourceCode":"\n    /// Either a BAML panic or a BAML error value.\n    #[error(\"{}\", format_unhandled_throw(value, trace))]\n    UnhandledThrow {\n        value: Box<BexExternalValue>,\n        trace: Vec<bex_vm::StackFrame>,\n    },\n\n    /// Clean process-termination request from `baml.sys.exit(code)`.\n    /// The caller is expected to honor this as the process exit code.\n    /// BAML `int` is `i64`, so the signal carries the full value; the\n    /// caller clamps into its shell's range (typically 0..=255 on Unix).\n    #[error(\"baml.sys.exit({code})\")]\n    Exit { code: i64 },\n\n    #[error(\"Cannot convert object of type {type_name}\")]\n    CannotConvert { type_name: String },\n\n    #[error(\"Type mismatch: {message}\")]\n    TypeMismatch { message: String },\n\n    #[error(\"Schema inconsistency: {message}\")]\n    SchemaInconsistency { message: String },\n\n    #[cfg(feature = \"heap_debug\")]\n    #[error(\"Snapshot not possible for type: {type_name}\")]\n    CannotSnapshot { type_name: String },\n\n    #[error(\"A function call with ID {call_id} is already in progress\")]\n    DuplicateCallId { call_id: CallId },\n\n    #[error(\"Package initialization failed: {0}\")]\n    InitFailed(String),\n\n    #[error(\"{0}\")]\n    Other(String),\n}","sourceCodeStart":827,"sourceCodeEnd":863,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bex_engine/src/lib.rs#L827-L863","documentation":"A generic type-mismatch failure at the engine boundary, with a human-readable message describing which types disagreed. Thrown when an operation receives a value of one BAML type where another was required and no coercion applies.","triggerScenarios":"Calling engine APIs with arguments of the wrong BAML type — e.g. passing a string where an int is expected to a function-lookup or value-conversion API; runtime checks in builtins rejecting argument types.","commonSituations":"Signature drift after refactoring BAML functions; passing loosely-typed host values into typed engine entry points; schema/function updates changing parameter types.","solutions":["Read the message to see which types mismatch and where","Correct the caller to pass the expected BAML type","Add explicit casts/coercions in BAML code where intentional","Add host-side validation of argument types before invoking"],"exampleFix":"// before\nengine.call(\"fn\", \"a string\") // expects int\n// after\nengine.call(\"fn\", 42)","handlingStrategy":"validation","validationCode":"fn assert_int(v: &BexExternalValue) -> Result<i64, EngineError> {\n    match v { BexExternalValue::Int(i) => Ok(*i), other => Err(EngineError::TypeMismatch { message: format!(\"expected int, got {:?}\", other) }) }\n}","typeGuard":"fn as_int(v: &BexExternalValue) -> Option<i64> {\n    if let BexExternalValue::Int(i) = v { Some(*i) } else { None }\n}","tryCatchPattern":"match result {\n    Err(EngineError::TypeMismatch { message }) => eprintln!(\"bad arg: {message}\"),\n    Ok(v) => use(v),\n    Err(e) => handle(e),\n}","preventionTips":["Validate argument types against the function signature before invoking","Keep BAML function signatures and host call sites in sync","Add integration tests over typed entry points"],"tags":["type-mismatch","types","baml"],"backgroundTag":"type-mismatch","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"}