{"record":{"id":"650d745df6b99770","repo":"BoundaryML/baml","slug":"trim-method-takes-no-arguments-at","errorCode":null,"errorMessage":"trim() method takes no arguments at {:?}","messagePattern":"trim\\(\\) method takes no arguments at (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":2864,"sourceCode":"        }\n        \"toUpperCase\" => {\n            let BamlValueWithMeta::String(s, _) = receiver else {\n                bail!(\n                    \"toUpperCase() method only available on strings at {:?}\",\n                    meta.0\n                );\n            };\n            if !args.is_empty() {\n                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);","sourceCodeStart":2846,"sourceCodeEnd":2882,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2846-L2882","documentation":"THIR interpreter runtime error: `trim()` was invoked with arguments. Like the other string methods, trim takes none, so extra arguments indicate a malformed call and evaluation bails at the method-call site.","triggerScenarios":"Writing `s.trim(charset)` or `s.trim(anything)` in a BAML expression — BAML does not support trimming a specific character set via arguments.","commonSituations":"Devs coming from Rust's trim_matches or other trim-with-set APIs pass a character/pattern argument; attempting to trim a specific character like a trailing newline by passing \"\\n\".","solutions":["Call trim() with no arguments: `s.trim()`.","If trimming a specific character is needed, use replace-style operations or handle it in the host language before the value enters BAML.","Verify the method name — includes()/startsWith() take one argument; trim does not."],"exampleFix":"// before\nlet clean = input.trim(\"\\n\");\n// after\nlet clean = input.trim();","handlingStrategy":"validation","validationCode":"const bad = src.match(/\\.trim\\s*\\(\\s*[^)]+/);\nif (bad) throw new Error('trim() takes no arguments: ' + bad[0]);","typeGuard":null,"tryCatchPattern":"try {\n  const res = await b.Function(args);\n} catch (e) {\n  if (String(e.message).includes('trim() method takes no arguments')) {\n    // remove the argument at the reported span and re-run\n  }\n  throw e;\n}","preventionTips":["Call trim() with empty parentheses only.","For character-set trimming, use replace operations or host-language string APIs.","Lint BAML files for `.trim(` with non-empty argument lists."],"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"}