langchain-ai/deepagents · error · ValueError

Provider name cannot be empty

Error message

Provider name cannot be empty

What it means

`set_stored_key` validates its inputs before touching the store and raises `ValueError` when the `provider` argument is empty (empty string or None). Provider names are the dictionary keys of the credential store, so an empty key would produce an unusable entry.

Source

Thrown at libs/code/deepagents_code/auth_store.py:471

            only for the `langsmith` tracing service. Whitespace is stripped;
            blank/`None` stores no project, meaning traces use the default
            project.

    Returns:
        A `WriteOutcome` whose `warnings` tuple lists chmod failures the
        caller should surface to the user. Empty on a clean save.

    Raises:
        ValueError: If `provider` or the stripped `key` is empty, or a non-empty
            `project` is paired with a provider other than the `langsmith`
            service.
        RuntimeError: If the credential file is corrupt and cannot be read, or
            the new file cannot be written (e.g. no disk space or an
            unwritable state directory).
    """  # noqa: DOC502 - `RuntimeError` re-raised from `_read_raw`/`_write_raw_or_raise`
    if not provider:
        msg = "Provider name cannot be empty"
        raise ValueError(msg)
    cleaned = key.strip()
    if not cleaned:
        msg = "API key cannot be empty"
        raise ValueError(msg)
    data = _read_raw() or {}
    creds = data.get("credentials")
    if not isinstance(creds, dict):
        creds = {}
    entry: dict[str, str] = {
        "type": "api_key",
        "key": cleaned,
        "added_at": datetime.now(tz=UTC).isoformat(timespec="seconds"),
    }
    cleaned_base_url = base_url.strip() if base_url else ""
    if cleaned_base_url:
        entry["base_url"] = cleaned_base_url
    cleaned_project = project.strip() if project else ""
    if cleaned_project:

View on GitHub (pinned to a1af029e6e)

Solutions

  1. Pass a non-empty provider name, e.g. set_stored_key("anthropic", key).
  2. Trim and check the provider string before calling; reject blank input in your own form/parser.
  3. If calling from `/auth`, enter the provider name when prompted instead of submitting empty input.

Example fix

// before
set_stored_key(provider.strip(), key)  # provider = "" -> ValueError
// after
provider = provider.strip()
if not provider:
    raise SystemExit("usage: /auth set <provider> <key>")
set_stored_key(provider, key)
Defensive patterns

Strategy: validation

Validate before calling

def require_provider(provider: str) -> str:
    cleaned = (provider or "").strip()
    if not cleaned:
        raise UsageError("provider name is required")
    return cleaned
# call site
set_stored_key(require_provider(provider), key)

Type guard

def _is_nonempty_str(value: object) -> TypeGuard[str]:
    return isinstance(value, str) and bool(value.strip())

Try / catch

try:
    set_stored_key(provider, key)
except ValueError as exc:
    if "Provider name cannot be empty" in str(exc):
        print("usage: /auth set <provider> <key>")
    else:
        raise

Prevention

When it happens

Trigger: Calling set_stored_key("") or set_stored_key(None, ...) directly, or via the `/auth set` flow (`_run_set` / `on_input_submitted`) when the user submits an empty provider name.

Common situations: Scripting the CLI from stdin and piping an empty first field; a UI form allowing blank provider input; string slicing/formatting bugs producing an empty provider variable.

Related errors


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