{"record":{"id":"d31a9809cd2ba4e4","repo":"BoundaryML/baml","slug":"length-method-not-available-on-type-at","errorCode":null,"errorMessage":"length() method not available on type {:?} at {:?}","messagePattern":"length\\(\\) method not available on type (.+?) at (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":2828,"sourceCode":"                    }\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                }\n                _ => bail!(\n                    \"length() method not available on type {:?} at {:?}\",\n                    receiver,\n                    meta.0\n                ),\n            }\n        }\n        \"toLowerCase\" => {\n            let BamlValueWithMeta::String(s, _) = receiver else {\n                bail!(\n                    \"toLowerCase() method only available on strings at {:?}\",\n                    meta.0\n                );\n            };\n            if !args.is_empty() {\n                bail!(\"toLowerCase() method takes no arguments at {:?}\", meta.0);\n            }\n            Ok(BamlValueWithMeta::String(s.to_lowercase(), meta.clone()))\n        }","sourceCodeStart":2810,"sourceCodeEnd":2846,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2810-L2846","documentation":"THIR interpreter runtime error: the `length()` method was invoked on a receiver type that has no length — not a list, string, or map (e.g. an int, bool, null, or class instance). The unsupported receiver type is echoed in the message along with the location metadata.","triggerScenarios":"Calling x.length() where x evaluates to a non-collection/non-string BamlValue, e.g. an integer field or a null.","commonSituations":"Assuming a value is a list or string when the upstream JSON shape differs (e.g. a single object instead of an array); calling length() on a number.","solutions":["Check the receiver's actual runtime type at the reported span","Guard or coerce: only call length() on values known to be string/list/map","If the value may be null or scalar, handle that case before calling length()"],"exampleFix":"// before\nlet n = count.length()\n// after\nlet n = items.length()  // items is a list","handlingStrategy":"type-guard","validationCode":"fn supports_length(v: &BamlValueWithMeta<ExprMetadata>) -> bool {\n    matches!(v, BamlValueWithMeta::List(_, _) | BamlValueWithMeta::String(_, _) | BamlValueWithMeta::Map(_, _))\n}","typeGuard":"fn supports_length(v: &BamlValueWithMeta<ExprMetadata>) -> bool {\n    matches!(v, BamlValueWithMeta::List(_, _) | BamlValueWithMeta::String(_, _) | BamlValueWithMeta::Map(_, _))\n}","tryCatchPattern":null,"preventionTips":["Confirm the runtime shape of parsed JSON before calling length()","Guard against null and scalar receivers","Prefer explicit type checks when upstream data shape can vary"],"tags":["baml","method-call","type-mismatch","length"],"backgroundTag":"unsupported-operation","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"}