langchain-ai/deepagents · error · ValueError

Profile key must be a non-empty string.

Error message

Profile key must be a non-empty string.

What it means

validate_profile_key enforces the `provider` or `provider:model` key shape used by harness and provider profile registries. The very first check rejects an empty string (or any falsy key) before any shape inspection. The library throws because an empty key can never identify a profile.

Source

Thrown at libs/deepagents/deepagents/profiles/_keys.py:28

def validate_profile_key(key: str) -> None:
    """Validate a profile registry key.

    Enforces the `provider` or `provider:model` shape used by the lookup
    functions. Rejects empty strings, whitespace-only or whitespace-padded
    halves, multiple colons, and empty halves.

    Args:
        key: The registry key to check.

    Raises:
        ValueError: If `key` is empty, contains leading/trailing whitespace,
            has more than one `:`, has whitespace adjacent to `:`, or has
            an empty half on either side of `:`.
    """
    if not key:
        msg = "Profile key must be a non-empty string."
        raise ValueError(msg)
    if key != key.strip():
        msg = f"Profile key {key!r} has leading or trailing whitespace; expected 'provider' or 'provider:model'."
        raise ValueError(msg)
    if key.count(":") > 1:
        msg = f"Profile key {key!r} has more than one ':'; expected 'provider' or 'provider:model'."
        raise ValueError(msg)
    if ":" in key:
        provider, _, model = key.partition(":")
        if not provider or not model:
            msg = f"Profile key {key!r} has an empty provider or model half; expected 'provider:model'."
            raise ValueError(msg)
        if provider != provider.strip() or model != model.strip():
            msg = f"Profile key {key!r} has whitespace adjacent to ':'; expected 'provider:model' with no spaces around ':'."
            raise ValueError(msg)

View on GitHub (pinned to a1af029e6e)

Solutions

  1. Supply a non-empty key such as 'anthropic' or 'anthropic:claude-sonnet-4'.
  2. Fix the config/env source so the profile name is actually populated.
  3. Check the value passed to register_harness_profile/register_provider_profile before calling.

Example fix

// before
register_provider_profile("")
// after
register_provider_profile("anthropic:claude-sonnet-4")
Defensive patterns

Strategy: validation

Validate before calling

def ensure_profile_key_ok(key: str) -> str:
    if not isinstance(key, str) or not key:
        raise ValueError("profile key must be a non-empty string")
    return key

Type guard

def is_nonempty_str(v: object) -> bool:
    return isinstance(v, str) and bool(v)

Try / catch

try:
    register_provider_profile(key)
except ValueError as e:
    if "non-empty" in str(e):
        logging.error("profile key missing: %s", e)
    else:
        raise

Prevention

When it happens

Trigger: Calling _register_harness_profile_impl or _register_provider_profile_impl (or the public register APIs that wrap them) with key="" or a value that is empty after being read from config/env.

Common situations: YAML/JSON profile config with `key:` left blank; env var or CLI flag for a profile name unset; programmatic registration passing an unpopulated variable.

Related errors


AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29). Data as JSON: /api/errors/705983c099089095. Report an issue: GitHub.