BoundaryML/baml · error

remap_role must be in allowed_roles: {}. Not found in {:?}

Error message

remap_role must be in allowed_roles: {}. Not found in {:?}

What it means

When both `allowed_roles` and `remap_roles` are set, every key in `remap_roles` must be a member of `allowed_roles`. Resolution fails if a remap source role is not in the allowed set, since remapping a disallowed role is meaningless.

Source

Thrown at engine/baml-lib/llm-client/src/clientspec.rs:380

            (Some(allowed), Some(default)) => {
                if !allowed.contains(default) {
                    return Err(anyhow::anyhow!("default_role must be in allowed_roles: {}. Not found in {:?}", default, allowed));
                }
            }
            (None, Some(default)) => {
                match default.as_str() {
                    "system" | "user" | "assistant" => {}
                    _ => return Err(anyhow::anyhow!("default_role must be one of 'system', 'user' or 'assistant': {}. Please specify \"allowed_roles\" if you want to use other custom default role.", default)),
                }
            }
            _ => {}
        }

        match (&allowed, &remap) {
            (Some(allowed), Some(remap)) => {
                for k in remap.keys() {
                    if !allowed.contains(k) {
                        return Err(anyhow::anyhow!(
                            "remap_role must be in allowed_roles: {}. Not found in {:?}",
                            k,
                            allowed
                        ));
                    }
                }
            }
            (None, Some(remap)) => {
                let allowed = ["system", "user", "assistant"]
                    .iter()
                    .map(|s| s.to_string())
                    .collect::<Vec<_>>();
                for k in remap.keys() {
                    if !allowed.contains(k) {
                        return Err(anyhow::anyhow!(
                            "remap_role must be in allowed_roles: {}. Not found in {:?}",
                            k,
                            allowed

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Add the remap key to allowed_roles.
  2. Remove the remap entry whose key is not in allowed_roles.
  3. Align remap_roles keys with the exact strings in allowed_roles (case-sensitive).

Example fix

// before
allowed_roles ["system", "user", "assistant"]
remap_roles { "developer" "system" }
// after
allowed_roles ["system", "user", "assistant", "developer"]
remap_roles { "developer" "system" }
Defensive patterns

Strategy: validation

Validate before calling

for (const key of Object.keys(remapRoles)) {
  if (!allowedRoles.includes(key)) {
    throw new Error(`remap key '${key}' missing from allowed_roles`);
  }
}

Prevention

When it happens

Trigger: Client spec resolve where allowed_roles=[...] and remap_roles contains a key not present in allowed_roles, e.g. remap_roles { "developer" "system" } with allowed_roles ["system","user","assistant"].

Common situations: Editing allowed_roles to a narrower list and forgetting to prune remap_roles entries that referenced previously allowed roles.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


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