{"record":{"id":"dad056576f928c94","repo":"BoundaryML/baml","slug":"includes-method-takes-exactly-1-argument-at","errorCode":null,"errorMessage":"includes() method takes exactly 1 argument at {:?}","messagePattern":"includes\\(\\) method takes exactly 1 argument at (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":2879,"sourceCode":"                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!(\n                    \"startsWith() method only available on strings at {:?}\",\n                    meta.0\n                );\n            };\n            if args.len() != 1 {\n                bail!(","sourceCodeStart":2861,"sourceCodeEnd":2897,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2861-L2897","documentation":"THIR interpreter runtime error: the `includes()` string method was invoked with an argument count other than exactly one (zero or multiple). includes takes a single string search argument; the arity check fails before any containment test runs.","triggerScenarios":"Calling `s.includes()` with no argument, or `s.includes(a, b)` with multiple arguments — BAML's includes does not support a start-position parameter like JavaScript's String.prototype.includes.","commonSituations":"Porting JavaScript code that uses `s.includes(sub, fromIndex)` and keeping the second argument; forgetting the argument entirely when converting from a different containment API.","solutions":["Pass exactly one string argument: `s.includes(search)`.","If a start-position search is needed, slice the string first or move the logic to the host language.","Confirm the method name and intended argument count against the BAML string method surface."],"exampleFix":"// before\nlet has = text.includes(\"key\", 10);\n// after\nlet has = text.slice(10).includes(\"key\");  // or drop the offset","handlingStrategy":"validation","validationCode":"const call = src.match(/\\.includes\\s*\\(([^)]*)\\)/);\nif (call && call[1].split(',').filter(a => a.trim()).length !== 1) {\n  throw new Error('includes() takes exactly 1 argument: ' + call[0]);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const res = await b.Function(args);\n} catch (e) {\n  if (String(e.message).includes('includes() method takes exactly 1 argument')) {\n    // fix arity at the reported span and re-run\n  }\n  throw e;\n}","preventionTips":["BAML's includes() has no start-index parameter — drop JS-style offsets.","For positional searches, slice the string first or move logic to the host language.","Lint for multiple arguments inside includes() calls in BAML sources."],"tags":["baml","interpreter","string-methods","wrong-arity"],"backgroundTag":"missing-required-argument","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"}