{"record":{"id":"e98d134c76f7e33a","repo":"BoundaryML/baml","slug":"split-method-only-available-on-strings-at","errorCode":null,"errorMessage":"split() method only available on strings at {:?}","messagePattern":"split\\(\\) method only available on strings at (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":2930,"sourceCode":"                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())\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","sourceCodeStart":2912,"sourceCodeEnd":2948,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2912-L2948","documentation":"The \"split\" string method is only defined for string receivers. When evaluate_method_call dispatches \"split\" it first pattern-matches the receiver as BamlValueWithMeta::String; any other receiver type (int, list, map, null, ...) triggers this bail. It exists because split(delimiter) has no meaning on non-string values in BAML's interpreter.","triggerScenarios":"Calling <non-string>.split(\",\") in a BAML expression, e.g. splitting a number or a list, or splitting a value that is null at runtime.","commonSituations":"Values returned from LLM extraction typed as numbers/lists but assumed to be strings; splitting the result of an expression that actually returns a list already; null values from optional fields being split.","solutions":["Check the receiver's actual type at the failing expression and make it a string first (explicit conversion or upstream type annotation fix).","If the value is already a list, drop the split call entirely — no delimiter-based splitting is needed.","Guard with a type check before calling split when the receiver type is dynamic."],"exampleFix":"// before (items is already a list)\nlet parts = items.split(\",\");\n\n// after\nlet parts = items;","handlingStrategy":"type-guard","validationCode":"// guard the receiver before split\nif (v is string) {\n  return v.split(\",\");\n} else if (v is string[]) {\n  return v;\n}","typeGuard":"fn is_string(v: BamlValue) -> bool { matches!(v, BamlValue::String(_)) }","tryCatchPattern":"match result {\n  Err(e) if e.to_string().contains(\"split() method only available on strings\") => default_split_result,\n  other => other,\n}","preventionTips":["Check whether the value is already a list — splitting a list is a common mistake.","Type-annotate extraction outputs as string when text is expected.","Handle null from optional fields before calling string methods."],"tags":["baml","type-mismatch","string-method","runtime"],"backgroundTag":"type-mismatch","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"}