BoundaryML/baml · error

project name `{name}` contains invalid character(s) {bad:?}.

Error message

project name `{name}` contains invalid character(s) {bad:?}. Use ASCII letters, digits, `-`, `_`, or `.`.

What it means

validate_project_name rejects names containing characters outside the whitelist of ASCII letters, digits, `-`, `_`, `.`. The name is interpolated into a quoted TOML string in baml.toml, so characters like `"` or control characters would produce an unparseable manifest; the check reports the exact offending characters.

Source

Thrown at baml_language/crates/baml_cli/src/init_command.rs:177

        .and_then(|s| s.to_str())
        .filter(|s| !s.is_empty())
        .map(|s| s.to_string())
}

/// Cargo-style project-name rules: non-empty, ASCII alphanumeric plus
/// `-`, `_`, `.`. Whitelist beats blacklist here — `render_baml_toml`
/// drops the name straight into a `"..."` TOML string, so a stray `"`
/// (or any control char) in the name produces an unparseable manifest.
fn validate_project_name(name: &str) -> Result<()> {
    if name.is_empty() {
        anyhow::bail!("project name cannot be empty");
    }
    let bad: Vec<char> = name
        .chars()
        .filter(|c| !(c.is_ascii_alphanumeric() || matches!(c, '-' | '_' | '.')))
        .collect();
    if !bad.is_empty() {
        anyhow::bail!(
            "project name `{name}` contains invalid character(s) {bad:?}. \
             Use ASCII letters, digits, `-`, `_`, or `.`."
        );
    }
    Ok(())
}

fn render_baml_toml(name: &str) -> String {
    format!(
        r#"[package]
name = "{name}"

# [scripts]
# dev = "-f main"

# Add a client generator, then generate its SDK:
#   baml generate add python/pydantic2
#   baml generate

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Rename using only ASCII letters, digits, `-`, `_`, `.` (e.g. `my-cool-app`).
  2. Put a human-friendly description elsewhere (e.g. edit baml.toml comments after init) instead of encoding it in the name.
  3. Sanitize the name in your script: strip or replace invalid characters before invoking `baml init`.

Example fix

// before
baml init ./app --name "My App!"
// after
baml init ./app --name "my-app"
Defensive patterns

Strategy: validation

Validate before calling

# guard: enforce Cargo-style name before init
echo "$NAME" | grep -qE '^[A-Za-z0-9._-]+$' || { echo "invalid project name: $NAME"; exit 1; }

Prevention

When it happens

Trigger: Run `baml init <path> --name` with a name containing spaces, slashes, quotes, unicode, or other non-whitelisted characters.

Common situations: Using a package display name like "My Cool App!", a path fragment like `a/b`, or copying a name with quotes into `--name`.

Understand the failure class

Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.

Related errors


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