{"record":{"id":"607f39f5ce7d4c83","repo":"BoundaryML/baml","slug":"split-argument-must-be-a-string-at","errorCode":null,"errorMessage":"split() argument must be a string at {:?}","messagePattern":"split\\(\\) argument must be a string at (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":2936,"sourceCode":"                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())\n                .map(|part| BamlValueWithMeta::String(part.to_string(), meta.clone()))\n                .collect();\n            Ok(BamlValueWithMeta::List(parts, meta.clone()))\n        }\n        \"substring\" => {\n            let BamlValueWithMeta::String(s, _) = receiver else {\n                bail!(\n                    \"substring() method only available on strings at {:?}\",\n                    meta.0\n                );\n            };\n            if args.len() != 2 {\n                bail!(\n                    \"substring() method takes exactly 2 arguments at {:?}\",\n                    meta.0","sourceCodeStart":2918,"sourceCodeEnd":2954,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2918-L2954","documentation":"The split method's delimiter argument must be a string. The interpreter destructures args[0] as a String value and bails with this message if it is an int, bool, list, or other non-string type. No implicit coercion is performed.","triggerScenarios":"Calling s.split(1), s.split(null), or passing a non-string variable/expression as the delimiter in a BAML expression.","commonSituations":"Numeric delimiters (e.g. splitting on a year or ID) not quoted; delimiter coming from extracted data typed as non-string; accidental reuse of a variable holding a list where a string was intended.","solutions":["Quote the delimiter or convert it to a string (e.g. n.to_string()) before passing it to split.","Verify the runtime type of the delimiter expression at the failing call site.","Add a type guard if the delimiter can be non-string at runtime."],"exampleFix":"// before\nlet parts = s.split(year); // year: int\n\n// after\nlet parts = s.split(year.to_string());","handlingStrategy":"type-guard","validationCode":"// ensure the delimiter is a string before split\n// delimiter must be string: quote literals, convert numbers","typeGuard":"fn is_string(v: BamlValue) -> bool { matches!(v, BamlValue::String(_)) }","tryCatchPattern":"match result {\n  Err(e) if e.to_string().contains(\"split() argument must be a string\") => use_default_delimiter,\n  other => other,\n}","preventionTips":["Always quote delimiter literals like \",\" or \"|\".","Convert numeric delimiters with to_string() first.","Keep delimiter values in string-typed variables to avoid accidental reuse."],"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"}