{"record":{"id":"021554c6e9e1e0db","repo":"BoundaryML/baml","slug":"tolowercase-method-only-available-on-strings-at","errorCode":null,"errorMessage":"toLowerCase() method only available on strings at {:?}","messagePattern":"toLowerCase\\(\\) method only available on strings at (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":2837,"sourceCode":"                        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        }\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);","sourceCodeStart":2819,"sourceCodeEnd":2855,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2819-L2855","documentation":"The .toLowerCase() method is defined only for string receivers. The interpreter throws this when toLowerCase() is invoked on a value of any other type, since there is no lowercase transformation defined for it.","triggerScenarios":"Calling x.toLowerCase() where x evaluates to a non-string BamlValue (int, list, map, null, etc.).","commonSituations":"Assuming user/LLM-produced data is a string when it parsed to a number or object; calling toLowerCase on an enum-ish field that is actually an object.","solutions":["Ensure the receiver is a string before calling toLowerCase()","Convert or extract a string first (e.g. use the string field of an object)","Add a guard so the method is only invoked on string values"],"exampleFix":"// before\nlet lower = id.toLowerCase()\n// after\nlet lower = id_str.toLowerCase()  // id_str is a string","handlingStrategy":"type-guard","validationCode":"fn supports_to_lowercase(v: &BamlValueWithMeta<ExprMetadata>) -> bool {\n    matches!(v, BamlValueWithMeta::String(_, _))\n}","typeGuard":"fn is_string(v: &BamlValueWithMeta<ExprMetadata>) -> bool {\n    matches!(v, BamlValueWithMeta::String(_, _))\n}","tryCatchPattern":null,"preventionTips":["Only call toLowerCase() on values known to be strings","Normalize/extract string fields before method calls","Validate parsed data shapes at boundaries"],"tags":["baml","method-call","type-mismatch","string"],"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"}