langchain-ai/deepagents · error · ValueError

Profile key {key!r} has whitespace adjacent to ':'; expected

Error message

Profile key {key!r} has whitespace adjacent to ':'; expected 'provider:model' with no spaces around ':'.

What it means

In 'provider:model' keys, whitespace adjacent to the ':' is rejected: both halves must already be stripped. This keeps 'a: b' and 'a:b' distinct-but-both-invalid, forcing canonical keys.

Source

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

            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. Strip each half before joining: f"{provider.strip()}:{model.strip()}".
  2. Normalize the config value (no space after ':' in the key value).
  3. Prefer yaml/json structured provider/model fields over manual string joining.

Example fix

// before
key = "anthropic : claude-3"
// after
key = "anthropic:claude-3"
Defensive patterns

Strategy: validation

Validate before calling

key = ":".join(p.strip() for p in key.split(":"))

Try / catch

try:
    register_provider_profile(key)
except ValueError as e:
    if "whitespace adjacent to ':'" in str(e):
        key = key.replace(" ", "")
    else:
        raise

Prevention

When it happens

Trigger: Building a key with a separator like ' : ' (e.g. f"{provider} : {model}") or joining user-entered fields without stripping.

Common situations: Pretty-printed config values copied verbatim ('anthropic: claude-3'); template strings with spaces around ':'; form input fields with stray spaces.

Related errors


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