langchain-ai/deepagents · error · ValueError
task() field `responseSchema` must be an object when provide
Error message
task() field `responseSchema` must be an object when provided
What it means
`_validate_task_payload` rejects a `responseSchema` field that is present but is not an object (Python dict). `responseSchema` is optional and describes the structured output shape the subagent should return. Raised as a ValueError before subagent dispatch.
Source
Thrown at libs/partners/quickjs/langchain_quickjs/_repl.py:566
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,
payload: dict[str, Any],
*,
state: _PTCState,
) -> Any:
"""Validate JS `task()` input and invoke the runner on the right loop.
The QuickJS host call runs on the REPL worker loop, but subagent runnables
should execute on the parent LangGraph loop when one exists so callbacks,
context, and async loop affinity match normal tool execution.
"""
validated = self._validate_task_payload(payload)
description, subagent_type, label, response_schema = validated
View on GitHub (pinned to a1af029e6e)
Solutions
- Pass a plain object schema, e.g. `responseSchema: {type: 'object', properties: {answer: {type: 'string'}}}`
- If you meant to reference a named schema, inline the full object instead
- Remove `responseSchema` if structured output is not needed
Example fix
// before
await task({ description: 'X', subagentType: 'researcher', responseSchema: 'AnswerSchema' })
// after
await task({ description: 'X', subagentType: 'researcher', responseSchema: { type: 'object', properties: { answer: { type: 'string' } } } }) Defensive patterns
Strategy: type-guard
Validate before calling
if (payload.responseSchema !== undefined && payload.responseSchema !== null
&& (typeof payload.responseSchema !== 'object' || Array.isArray(payload.responseSchema))) {
throw new Error('responseSchema must be an object');
} Type guard
function isValidResponseSchema(v) {
return v === undefined || v === null
|| (typeof v === 'object' && v !== null && !Array.isArray(v));
} Try / catch
try {
await task(payload);
} catch (e) {
if (String(e).includes('responseSchema')) {
delete payload.responseSchema; // structured output is optional
return await task(payload);
}
throw e;
} Prevention
- Pass inline JSON-schema objects, never schema names or JSON strings
- Arrays are not valid — wrap items in an object schema
- Omit responseSchema when no structured output is required
When it happens
Trigger: JS calls `task({..., responseSchema: 'name'})` passing a string, array, boolean, or other non-object value where a JSON object schema is expected.
Common situations: Model-generated JS passing a schema name instead of an inline schema object, marshaling a JS array where an object was intended, or double-encoding the schema as a JSON string.
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
- task() requires non-empty string field `description`
- task() requires non-empty string field `subagentType`
- task() field `label` must be a string when provided
- task() requires an active ToolRuntime
- task tool not configured for this eval
AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29).
Data as JSON: /api/errors/330c4aa6e09c55b1.
Report an issue: GitHub.