{"record":{"id":"ed90036d86500b9a","repo":"BoundaryML/baml","slug":"length-method-takes-no-arguments-at","errorCode":null,"errorMessage":"length() method takes no arguments at {:?}","messagePattern":"length\\(\\) method takes no arguments at (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":2809,"sourceCode":"            Ok(parsed_value)\n        }\n        _ => bail!(\"unknown builtin function '{}' at {:?}\", fn_name, meta.0),\n    }\n}\n\nfn evaluate_method_call(\n    receiver: &BamlValueWithMeta<ExprMetadata>,\n    method_name: &str,\n    args: &[BamlValueWithMeta<ExprMetadata>],\n    meta: &ExprMetadata,\n) -> Result<BamlValueWithMeta<ExprMetadata>> {\n    match method_name {\n        \"length\" => {\n            // Array/List/String/Map length method\n            match receiver {\n                BamlValueWithMeta::List(items, _) => {\n                    if !args.is_empty() {\n                        bail!(\"length() method takes no arguments at {:?}\", meta.0);\n                    }\n                    Ok(BamlValueWithMeta::Int(items.len() as i64, meta.clone()))\n                }\n                BamlValueWithMeta::String(s, _) => {\n                    if !args.is_empty() {\n                        bail!(\"length() method takes no arguments at {:?}\", meta.0);\n                    }\n                    Ok(BamlValueWithMeta::Int(\n                        s.chars().count() as i64,\n                        meta.clone(),\n                    ))\n                }\n                BamlValueWithMeta::Map(map, _) => {\n                    if !args.is_empty() {\n                        bail!(\"length() method takes no arguments at {:?}\", meta.0);\n                    }\n                    Ok(BamlValueWithMeta::Int(map.len() as i64, meta.clone()))\n                }","sourceCodeStart":2791,"sourceCodeEnd":2827,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2791-L2827","documentation":"THIR interpreter runtime error: the `length()` method was invoked with one or more arguments. The builtin length method on lists, strings, and maps takes none; extra arguments mean the call site is malformed (perhaps intending a different function), and evaluation aborts with the method-call location.","triggerScenarios":"Evaluating someList.length(x) or someList.length(a, b) where someList is a BamlValueWithMeta::List.","commonSituations":"Confusing length() with functions in other languages that take a predicate or separator; mechanically converting len(list) style calls from Python.","solutions":["Remove all arguments from the length() call","If filtering by a predicate is intended, filter the list first, then call length()"],"exampleFix":"// before\nlet n = items.length(0)\n// after\nlet n = items.length()","handlingStrategy":"validation","validationCode":"fn validate_length_call(args: &[BamlValueWithMeta<ExprMetadata>]) -> Result<(), String> {\n    if !args.is_empty() {\n        return Err(\"length() takes no arguments\".into());\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never pass arguments to length()","Filter before counting if needed","Lint generated expressions for non-empty arg lists on zero-arg methods"],"tags":["baml","method-call","arity","length"],"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-14T11:17:12.474Z"}