langchain-ai/deepagents · error · TypeError

`system_prompt` must be str or None, got {type(system_prompt

Error message

`system_prompt` must be str or None, got {type(system_prompt).__name__}

What it means

from_dict requires `system_prompt` to be a str or None. Non-string values raise TypeError, because the prompt is interpolated directly into the agent's instructions and must be text.

Source

Thrown at libs/deepagents/deepagents/profiles/harness/harness_profiles.py:187

            TypeError: If `data` contains unknown keys, or if any value has
                the wrong type.
        """
        unknown = set(data.keys()) - _GENERAL_PURPOSE_SUBAGENT_KEYS
        if unknown:
            msg = f"Unknown keys in GeneralPurposeSubagentProfile dict: {sorted(unknown)}"
            raise TypeError(msg)
        enabled = data.get("enabled")
        description = data.get("description")
        system_prompt = data.get("system_prompt")
        if enabled is not None and not isinstance(enabled, bool):
            msg = f"`enabled` must be bool or None, got {type(enabled).__name__}"
            raise TypeError(msg)
        if description is not None and not isinstance(description, str):
            msg = f"`description` must be str or None, got {type(description).__name__}"
            raise TypeError(msg)
        if system_prompt is not None and not isinstance(system_prompt, str):
            msg = f"`system_prompt` must be str or None, got {type(system_prompt).__name__}"
            raise TypeError(msg)
        return cls(enabled=enabled, description=description, system_prompt=system_prompt)


@dataclass(frozen=True)
class HarnessProfileConfig:
    """Declarative harness-profile config for YAML/JSON-backed profiles.

    !!! beta

        `deepagents.profiles` exposes beta APIs that may receive minor changes in
        future releases. Refer to the [versioning documentation](https://docs.langchain.com/oss/python/versioning)
        for more details.

    A `HarnessProfileConfig` contains the file-friendly subset of harness
    settings: plain strings, bools, lists, and nested dicts that can be loaded
    from YAML or JSON. For in-code/runtime-only adjustments such as
    `extra_middleware` or class-form `excluded_middleware`, use
    `HarnessProfile` instead.

View on GitHub (pinned to a1af029e6e)

Solutions

  1. Flatten to a single string before calling from_dict.
  2. Join chunks: '\n'.join(prompt_parts).
  3. Use the framework's message-list API instead of system_prompt if a structured prompt is needed.

Example fix

// before
from_dict({"system_prompt": ["You are", "an agent"]})
// after
from_dict({"system_prompt": "You are an agent"})
Defensive patterns

Strategy: type-guard

Validate before calling

if not (system_prompt is None or isinstance(system_prompt, str)):
    raise TypeError("system_prompt must be str or None")

Type guard

def is_str_or_none(v: object) -> bool:
    return v is None or isinstance(v, str)

Try / catch

try:
    profile = GeneralPurposeSubagentProfile.from_dict(data)
except TypeError as e:
    logging.error("bad 'system_prompt' value: %s", e)

Prevention

When it happens

Trigger: Passing {'system_prompt': 42}, a list of prompt chunks, or a nested dict/structured prompt object to GeneralPurposeSubagentProfile.from_dict.

Common situations: Structured prompt configs (arrays of messages) from other frameworks pasted into the profile config; numeric defaults; YAML flow lists where a scalar was intended.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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