langchain-ai/deepagents · error · ModelConfigError
Could not apply {label} to model '{model_name}': {exc}. The
Error message
Could not apply {label} to model '{model_name}': {exc}. The model may not support profile assignment. What it means
Raised (when `raise_on_failure=True`) by `_apply_profile_overrides` if assigning the merged profile dict onto `model.profile` fails with AttributeError/TypeError/ValueError, meaning the chat model object does not accept profile assignment.
Source
Thrown at libs/code/deepagents_code/config.py:5631
Raises:
ModelConfigError: If `raise_on_failure` is `True` and the model
rejects profile assignment.
"""
from deepagents_code.model_config import ModelConfigError
logger.debug("Applying %s profile overrides: %s", label, overrides)
profile = getattr(model, "profile", None)
merged = {**profile, **overrides} if isinstance(profile, dict) else overrides
try:
model.profile = merged # ty: ignore[invalid-assignment]
except (AttributeError, TypeError, ValueError) as exc:
if raise_on_failure:
msg = (
f"Could not apply {label} to model '{model_name}': {exc}. "
f"The model may not support profile assignment."
)
raise ModelConfigError(msg) from exc
logger.warning(
"Could not apply %s profile overrides to model '%s': %s. "
"Overrides will be ignored.",
label,
model_name,
exc,
)
def create_model(
model_spec: str | None = None,
*,
extra_kwargs: dict[str, Any] | None = None,
profile_overrides: dict[str, Any] | None = None,
cli_max_retries: int | None = None,
) -> ModelResult:
"""Create a chat model.
View on GitHub (pinned to a1af029e6e)
Solutions
- Set `raise_on_failure=False` (the default) so overrides are ignored with a warning instead of failing model creation.
- Use a model class that supports mutable `profile` assignment (standard langchain chat models do).
- Drop the profile override for that model, or apply the capability flags another way.
- Check the chained exception for which attribute/assignment failed.
Example fix
// before _apply_profile_overrides(model, overrides, name, label="cli", raise_on_failure=True) // after _apply_profile_overrides(model, overrides, name, label="cli", raise_on_failure=False) # warn + ignore instead
Defensive patterns
Strategy: fallback
Validate before calling
profile = getattr(model, "profile", None) can_assign = isinstance(profile, dict) or (profile is None and not hasattr(type(model), "__slots__")) # only request raise_on_failure=True when can_assign
Try / catch
try:
_apply_profile_overrides(model, overrides, name, label=label, raise_on_failure=True)
except ModelConfigError:
logger.warning("Profile overrides unsupported for %s; continuing without them", name) Prevention
- Leave raise_on_failure=False (default) unless override application is mandatory
- Target profile overrides only at standard langchain chat models
- Verify the custom model class has a writable profile attribute before enabling overrides
- Confirm the langchain version's profile schema matches your override keys
When it happens
Trigger: `create_model` with profile overrides (config.toml or `--profile-override`) applied to a custom `BaseChatModel` whose `profile` attribute is read-only, absent in a way that rejects setattr, or validated against a strict schema.
Common situations: Third-party or custom model classes with frozen/slot-based attributes, provider integrations where `profile` is a property without a setter, langchain version where profile shape changed.
Related errors
- Unable to infer a model provider for {model_spec!r}. Specify
- Invalid model configuration for '{provider}:{model_name}': {
- '{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/014da6e13e0790df.
Report an issue: GitHub.