BoundaryML/baml · error

toLowerCase() method only available on strings at {:?}

Error message

toLowerCase() method only available on strings at {:?}

What it means

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.

Source

Thrown at engine/baml-compiler/src/thir/interpret.rs:2837

                        meta.clone(),
                    ))
                }
                BamlValueWithMeta::Map(map, _) => {
                    if !args.is_empty() {
                        bail!("length() method takes no arguments at {:?}", meta.0);
                    }
                    Ok(BamlValueWithMeta::Int(map.len() as i64, meta.clone()))
                }
                _ => bail!(
                    "length() method not available on type {:?} at {:?}",
                    receiver,
                    meta.0
                ),
            }
        }
        "toLowerCase" => {
            let BamlValueWithMeta::String(s, _) = receiver else {
                bail!(
                    "toLowerCase() method only available on strings at {:?}",
                    meta.0
                );
            };
            if !args.is_empty() {
                bail!("toLowerCase() method takes no arguments at {:?}", meta.0);
            }
            Ok(BamlValueWithMeta::String(s.to_lowercase(), meta.clone()))
        }
        "toUpperCase" => {
            let BamlValueWithMeta::String(s, _) = receiver else {
                bail!(
                    "toUpperCase() method only available on strings at {:?}",
                    meta.0
                );
            };
            if !args.is_empty() {
                bail!("toUpperCase() method takes no arguments at {:?}", meta.0);

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Ensure the receiver is a string before calling toLowerCase()
  2. Convert or extract a string first (e.g. use the string field of an object)
  3. Add a guard so the method is only invoked on string values

Example fix

// before
let lower = id.toLowerCase()
// after
let lower = id_str.toLowerCase()  // id_str is a string
Defensive patterns

Strategy: type-guard

Validate before calling

fn supports_to_lowercase(v: &BamlValueWithMeta<ExprMetadata>) -> bool {
    matches!(v, BamlValueWithMeta::String(_, _))
}

Type guard

fn is_string(v: &BamlValueWithMeta<ExprMetadata>) -> bool {
    matches!(v, BamlValueWithMeta::String(_, _))
}

Prevention

When it happens

Trigger: Calling x.toLowerCase() where x evaluates to a non-string BamlValue (int, list, map, null, etc.).

Common situations: 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.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/021554c6e9e1e0db. Report an issue: GitHub.