langchain-ai/deepagents · error · ValueError

task() requires non-empty string field `subagentType`

Error message

task() requires non-empty string field `subagentType`

What it means

`_validate_task_payload` rejects JS `task()` calls whose payload has no `subagentType` field, or whose `subagentType` is not a non-empty string. The subagent type selects which configured subagent runs the task; without it dispatch cannot proceed. Raised as a ValueError before subagent dispatch.

Source

Thrown at libs/partners/quickjs/langchain_quickjs/_repl.py:553

    @staticmethod
    def _validate_task_payload(
        payload: dict[str, Any],
    ) -> tuple[str, str, str | None, dict[str, Any] | None]:
        """Validate JS `task()` input and return its typed fields.

        JS callers pass camelCase keys (`subagentType`, `responseSchema`) as
        documented in the system prompt; the returned tuple is snake_case for
        the Python dispatch path.
        """
        description = payload.get("description")
        if not isinstance(description, str) or not description:
            msg = "task() requires non-empty string field `description`"
            raise ValueError(msg)

        subagent_type = payload.get("subagentType")
        if not isinstance(subagent_type, str) or not subagent_type:
            msg = "task() requires non-empty string field `subagentType`"
            raise ValueError(msg)

        raw_label = payload.get("label")
        if raw_label is not None and not isinstance(raw_label, str):
            msg = "task() field `label` must be a string when provided"
            raise ValueError(msg)
        label = raw_label.strip() if isinstance(raw_label, str) else None
        if label == "":
            label = None

        response_schema = payload.get("responseSchema")
        if response_schema is not None and not isinstance(response_schema, dict):
            msg = "task() field `responseSchema` must be an object when provided"
            raise ValueError(msg)

        return description, subagent_type, label, response_schema

    async def _ainvoke_task_on_outer_loop(
        self,

View on GitHub (pinned to a1af029e6e)

Solutions

  1. Pass a non-empty string `subagentType` matching a configured subagent: `task({description: 'X', subagentType: 'researcher'})`
  2. Verify the subagentType name against the subagents configured for the eval
  3. Fix prompt/schema so the model emits camelCase `subagentType`

Example fix

// before
await task({ description: 'Search docs', subagent_type: 'researcher' })
// after
await task({ description: 'Search docs', subagentType: 'researcher' })
Defensive patterns

Strategy: validation

Validate before calling

function canCallTask(p) {
  return typeof p === 'object' && p !== null
    && typeof p.subagentType === 'string' && p.subagentType.length > 0;
}

Type guard

function isNonEmptyString(v) {
  return typeof v === 'string' && v.length > 0;
}

Try / catch

try {
  await task(payload);
} catch (e) {
  if (String(e).includes('subagentType')) {
    throw new Error('task() payload missing non-empty subagentType');
  }
  throw e;
}

Prevention

When it happens

Trigger: JS calls `task({description: '...'})` with `subagentType` missing, `undefined`, `null`, non-string, or `''`.

Common situations: Model-generated JS forgetting the second required field, using snake_case `subagent_type` instead of camelCase `subagentType`, or passing a JS value that marshals to a non-string (e.g. a number or object).

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/268f49b4aea0a8c6. Report an issue: GitHub.