langchain-ai/deepagents · error · UnknownProviderError
Unable to infer a model provider for {model_spec!r}. Specify
Error message
Unable to infer a model provider for {model_spec!r}. Specify one explicitly (e.g. 'anthropic:{model_spec}') or see the provider reference at {docs_url}. What it means
Raised when `create_model` cannot determine which provider to use for a model spec. Both the app's auto-detection (`detect_provider`) and `init_chat_model`'s own inference failed, so a structured `UnknownProviderError` is raised so the UI can render the provider-reference docs URL as a clickable link.
Source
Thrown at libs/code/deepagents_code/config.py:5506
else:
if hint.command is not None:
install_hint = f"Install with: {hint.command}"
else:
install_hint = f"Install the '{package}' package manually"
msg = (
f"Missing package for provider '{provider}'. "
f"{install_hint}, then retry with `/model`."
)
raise MissingProviderPackageError(
msg, provider=provider, package=package
) from e
raise ModelConfigError(msg) from e
except (ValueError, TypeError) as e:
if not provider:
# Both app auto-detection and `init_chat_model`'s own inference
# failed; surface a structured error so the UI can render the
# docs URL as a clickable link.
raise UnknownProviderError(model_spec=model_name) from e
spec = f"{provider}:{model_name}"
msg = f"Invalid model configuration for '{spec}': {e}"
raise ModelConfigError(msg) from e
except Exception as e: # provider SDK auth/network errors
spec = f"{provider}:{model_name}" if provider else model_name
msg = f"Failed to initialize model '{spec}': {e}"
raise ModelConfigError(msg) from e
@dataclass(frozen=True)
class ModelResult:
"""Result of creating a chat model, bundling the model with its metadata.
This separates model creation from runtime-state mutation so callers can
decide when to commit the metadata to process-wide state.
Attributes:
model: The instantiated chat model.View on GitHub (pinned to a1af029e6e)
Solutions
- Add an explicit provider prefix: use 'anthropic:my-model' instead of 'my-model'.
- Set a default model spec in config.toml or the relevant env var so `create_model()` has a fully qualified default.
- Check the model name for typos against the provider's official model list.
- Install the provider package (e.g. langchain-anthropic) — missing packages can prevent inference.
Example fix
// before
model = create_model("my-weird-model-id")
// after
model = create_model("anthropic:my-weird-model-id") Defensive patterns
Strategy: validation
Validate before calling
def has_provider_hint(spec: str) -> bool:
if ":" in spec:
return True
known_prefixes = ("gpt-", "o1", "o3", "claude", "gemini", "grok", "command", "bedrock/")
return spec.lower().startswith(known_prefixes)
# call create_model only when has_provider_hint(spec), else pass "provider:" + spec Try / catch
try:
result = create_model(spec)
except UnknownProviderError:
result = create_model(f"anthropic:{spec}") # or prompt user for provider Prevention
- Always qualify non-standard model ids with an explicit 'provider:' prefix
- Set a default model spec in config.toml so bare create_model() never needs inference
- Keep the provider package installed so init_chat_model inference works
- Verify model names against the provider's official docs
When it happens
Trigger: Calling `create_model()` or `create_model(model_spec)` with a bare model name (no `provider:` prefix) whose name matches no known prefix, no default model is configured, and no provider can be inferred from environment credentials — and `init_chat_model` also raises ValueError/TypeError during inference.
Common situations: Typos in model names ('claud-sonnet-4-5'), obscure or custom model IDs not in `detect_provider`'s prefix list, missing default in config.toml or env, using a new provider model before the app knows its prefix.
Related errors
- Invalid model configuration for '{provider}:{model_name}': {
- Could not apply {label} to model '{model_name}': {exc}. The
- '{class_path}' is not a BaseChatModel subclass (got {type(cl
- Missing package for provider '{provider}'. {install_hint}, t
- Provider package '{package}' is installed but failed to impo
AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29).
Data as JSON: /api/errors/dc7f9908e73060d1.
Report an issue: GitHub.