{"record":{"id":"d71eeb34b1ea47b6","repo":"BoundaryML/baml","slug":"startswith-method-only-available-on-strings-at","errorCode":null,"errorMessage":"startsWith() method only available on strings at {:?}","messagePattern":"startsWith\\(\\) method only available on strings at (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":2891,"sourceCode":"                bail!(\n                    \"includes() method only available on strings at {:?}\",\n                    meta.0\n                );\n            };\n            if args.len() != 1 {\n                bail!(\"includes() method takes exactly 1 argument at {:?}\", meta.0);\n            }\n            let BamlValueWithMeta::String(search, _) = &args[0] else {\n                bail!(\"includes() argument must be a string at {:?}\", meta.0);\n            };\n            Ok(BamlValueWithMeta::Bool(\n                s.contains(search.as_str()),\n                meta.clone(),\n            ))\n        }\n        \"startsWith\" => {\n            let BamlValueWithMeta::String(s, _) = receiver else {\n                bail!(\n                    \"startsWith() method only available on strings at {:?}\",\n                    meta.0\n                );\n            };\n            if args.len() != 1 {\n                bail!(\n                    \"startsWith() method takes exactly 1 argument at {:?}\",\n                    meta.0\n                );\n            }\n            let BamlValueWithMeta::String(prefix, _) = &args[0] else {\n                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        }","sourceCodeStart":2873,"sourceCodeEnd":2909,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2873-L2909","documentation":"THIR interpreter runtime error: the `startsWith()` method was invoked on a receiver that is not a String (e.g. a list, int, or null). The receiver type guard fails before the method body runs, aborting evaluation at the call site.","triggerScenarios":"Calling `x.startsWith(prefix)` where `x` is a non-string value — int, float, bool, null, map, array — at runtime.","commonSituations":"Assuming an identifier or version field is a string when it parses as a number; calling startsWith on the result of a function whose return type changed; applying it to a null optional without checking.","solutions":["Coerce the receiver to a string before the call (interpolation or explicit conversion).","Fix the upstream declaration so the receiver is a string.","Branch on the receiver's type before calling startsWith().","Use the reported span to locate and correct the receiver expression."],"exampleFix":"// before\nlet isV2 = apiVersion.startsWith(\"2\");  // apiVersion is a number\n// after\nlet isV2 = \"{{ apiVersion }}\".startsWith(\"2\");","handlingStrategy":"type-guard","validationCode":"if (typeof value !== 'string') {\n  throw new Error('startsWith() receiver must be a string, got: ' + typeof value);\n}","typeGuard":"const isStr = (v) => typeof v === 'string';","tryCatchPattern":"try {\n  const res = await b.Function(args);\n} catch (e) {\n  if (String(e.message).includes('startsWith() method only available on strings')) {\n    // stringify the receiver or fix its declared type and retry\n  }\n  throw e;\n}","preventionTips":["Ensure prefix-checked values (versions, paths, IDs) are declared as strings.","Coerce numeric fields via interpolation before prefix checks.","Null-check optional receivers before calling string methods.","Re-check receiver types after any schema/type refactor."],"tags":["baml","interpreter","string-methods","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-23T08:17:48.524Z"}