{"record":{"id":"97b67e56379c1ac4","repo":"BoundaryML/baml","slug":"includes-method-only-available-on-strings-at","errorCode":null,"errorMessage":"includes() method only available on strings at {:?}","messagePattern":"includes\\(\\) method only available on strings at (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":2873,"sourceCode":"                bail!(\"toUpperCase() method takes no arguments at {:?}\", meta.0);\n            }\n            Ok(BamlValueWithMeta::String(s.to_uppercase(), meta.clone()))\n        }\n        \"trim\" => {\n            let BamlValueWithMeta::String(s, _) = receiver else {\n                bail!(\"trim() method only available on strings at {:?}\", meta.0);\n            };\n            if !args.is_empty() {\n                bail!(\"trim() method takes no arguments at {:?}\", meta.0);\n            }\n            Ok(BamlValueWithMeta::String(\n                s.trim().to_string(),\n                meta.clone(),\n            ))\n        }\n        \"includes\" => {\n            let BamlValueWithMeta::String(s, _) = receiver else {\n                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!(","sourceCodeStart":2855,"sourceCodeEnd":2891,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2855-L2891","documentation":"includes() performs a substring containment check and is defined only for string receivers in the BAML interpreter. If the receiver is not a string, evaluate_method_call bails with this error before the containment check runs.","triggerScenarios":"Calling `x.includes(sub)` where `x` is a non-string value — an array, map, int, bool, or null — expecting JavaScript-like behavior on arrays or other containers.","commonSituations":"Devs familiar with JavaScript's Array.prototype.includes call it on a BAML array/list; checking containment in a map value that isn't a string; a variable inferred as non-string at runtime though the code assumed string.","solutions":["Convert the receiver to a string before calling includes(), if string containment was intended.","For arrays/lists, use the appropriate list membership expression instead of includes() (BAML's includes is string-only).","Add a type check/branch on the receiver before calling includes().","Use the error span to identify the receiver expression and correct its type."],"exampleFix":"// before\nlet found = tags.includes(\"admin\");      // tags is a list\n// after\nlet found = \"{{ tags }}\".includes(\"admin\");  // or use list membership","handlingStrategy":"type-guard","validationCode":"if (typeof receiver !== 'string') {\n  throw new Error('includes() receiver must be a string; use list membership for arrays');\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('includes() method only available on strings')) {\n    // switch to string coercion or list membership expression\n  }\n  throw e;\n}","preventionTips":["Do not assume BAML's includes() works on arrays like JavaScript's Array.includes.","Use list membership syntax for container containment checks.","Stringify values before containment checks when types vary.","Verify receiver types whenever refactoring expression blocks."],"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"}