{"record":{"id":"265e3a2bd457a34e","repo":"BoundaryML/baml","slug":"includes-argument-must-be-a-string-at","errorCode":null,"errorMessage":"includes() argument must be a string at {:?}","messagePattern":"includes\\(\\) argument must be a string at (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":2882,"sourceCode":"                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!(\n                    \"startsWith() method takes exactly 1 argument at {:?}\",\n                    meta.0\n                );","sourceCodeStart":2864,"sourceCodeEnd":2900,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2864-L2900","documentation":"The single argument passed to includes() must itself be a string; if it evaluates to any other BAML type, evaluate_method_call bails. The containment check is implemented as Rust's str::contains, which requires a string needle.","triggerScenarios":"Calling `s.includes(x)` where `x` is an int, bool, null, array, or map — e.g. searching for a numeric token without quoting it.","commonSituations":"Searching for a number without converting it to a string (e.g. includes(version) where version is an int); passing a null optional value as the needle; nested field from JSON input assumed to be a string.","solutions":["Convert the argument to a string (string interpolation or explicit conversion) before passing it: `s.includes(\"{{ x }}\")`.","Fix the declaration of the needle variable so it is a string type.","Guard with a type check when the needle may be null or another type.","Check the error span to find the argument expression and fix its type."],"exampleFix":"// before\nlet has = text.includes(errorCode);   // errorCode is an int\n// after\nlet has = text.includes(\"{{ errorCode }}\");","handlingStrategy":"type-guard","validationCode":"if (typeof needle !== 'string') {\n  throw new Error('includes() argument must be a string, got: ' + typeof needle);\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() argument must be a string')) {\n    // coerce the argument with string interpolation and retry\n  }\n  throw e;\n}","preventionTips":["Quote numeric literals used as search needles.","Convert numbers/bools to strings with interpolation before containment checks.","Guard nullable fields before using them as search arguments.","Type JSON-derived fields explicitly as strings when they feed string methods."],"tags":["baml","interpreter","string-methods","argument-type"],"backgroundTag":"invalid-argument-value","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"}