{"record":{"id":"3ad2025e2e57c39d","repo":"BoundaryML/baml","slug":"endswith-argument-must-be-a-string-at","errorCode":null,"errorMessage":"endsWith() argument must be a string at {:?}","messagePattern":"endsWith\\(\\) argument must be a string at (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":2921,"sourceCode":"                bail!(\"startsWith() argument must be a string at {:?}\", meta.0);\n            };\n            Ok(BamlValueWithMeta::Bool(\n                s.starts_with(prefix.as_str()),\n                meta.clone(),\n            ))\n        }\n        \"endsWith\" => {\n            let BamlValueWithMeta::String(s, _) = receiver else {\n                bail!(\n                    \"endsWith() method only available on strings at {:?}\",\n                    meta.0\n                );\n            };\n            if args.len() != 1 {\n                bail!(\"endsWith() method takes exactly 1 argument at {:?}\", meta.0);\n            }\n            let BamlValueWithMeta::String(suffix, _) = &args[0] else {\n                bail!(\"endsWith() argument must be a string at {:?}\", meta.0);\n            };\n            Ok(BamlValueWithMeta::Bool(\n                s.ends_with(suffix.as_str()),\n                meta.clone(),\n            ))\n        }\n        \"split\" => {\n            let BamlValueWithMeta::String(s, _) = receiver else {\n                bail!(\"split() method only available on strings at {:?}\", meta.0);\n            };\n            if args.len() != 1 {\n                bail!(\"split() method takes exactly 1 argument at {:?}\", meta.0);\n            }\n            let BamlValueWithMeta::String(delimiter, _) = &args[0] else {\n                bail!(\"split() argument must be a string at {:?}\", meta.0);\n            };\n            let parts: Vec<BamlValueWithMeta<ExprMetadata>> = s\n                .split(delimiter.as_str())","sourceCodeStart":2903,"sourceCodeEnd":2939,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2903-L2939","documentation":"The endsWith method's single argument must be a string. The interpreter destructures args[0] as BamlValueWithMeta::String and bails with this message if it is an int, bool, list, or other value type. The library throws it rather than coercing non-string arguments.","triggerScenarios":"Calling s.endsWith(5), s.endsWith(myIntVar), s.endsWith(null), or passing a list/bool as the suffix in a BAML expression.","commonSituations":"Numeric literals or extracted numeric values passed as the suffix without conversion; variables from structured extraction that are not strings; typos where an int variable shadows the intended string.","solutions":["Convert the argument to a string (e.g. use .to_string() on the value or a string literal) before passing it to endsWith.","Verify the type of the expression passed as the argument at the failing call site.","Add a type guard around the call if the argument can be a non-string at runtime."],"exampleFix":"// before\nlet ok = s.endsWith(version); // version: int\n\n// after\nlet ok = s.endsWith(version.to_string());","handlingStrategy":"type-guard","validationCode":"// ensure the suffix argument is a string before the call\n// suffix must be string: literal or converted value","typeGuard":"fn is_string(v: BamlValue) -> bool { matches!(v, BamlValue::String(_)) }","tryCatchPattern":"match result {\n  Err(e) if e.to_string().contains(\"argument must be a string\") => use_default_suffix,\n  other => other,\n}","preventionTips":["Quote suffix literals instead of passing raw numbers.","Convert numeric/enum values with to_string() before using them as method arguments.","Keep suffix values in string-typed variables."],"tags":["baml","argument-type","string-method","type-mismatch"],"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"}