{"record":{"id":"4fa734701576c1dc","repo":"langchain-ai/deepagents","slug":"task-field-label-must-be-a-string-when-provide","errorCode":null,"errorMessage":"task() field `label` must be a string when provided","messagePattern":"task\\(\\) field `label` must be a string when provided","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/partners/quickjs/langchain_quickjs/_repl.py","lineNumber":558,"sourceCode":"\n        JS callers pass camelCase keys (`subagentType`, `responseSchema`) as\n        documented in the system prompt; the returned tuple is snake_case for\n        the Python dispatch path.\n        \"\"\"\n        description = payload.get(\"description\")\n        if not isinstance(description, str) or not description:\n            msg = \"task() requires non-empty string field `description`\"\n            raise ValueError(msg)\n\n        subagent_type = payload.get(\"subagentType\")\n        if not isinstance(subagent_type, str) or not subagent_type:\n            msg = \"task() requires non-empty string field `subagentType`\"\n            raise ValueError(msg)\n\n        raw_label = payload.get(\"label\")\n        if raw_label is not None and not isinstance(raw_label, str):\n            msg = \"task() field `label` must be a string when provided\"\n            raise ValueError(msg)\n        label = raw_label.strip() if isinstance(raw_label, str) else None\n        if label == \"\":\n            label = None\n\n        response_schema = payload.get(\"responseSchema\")\n        if response_schema is not None and not isinstance(response_schema, dict):\n            msg = \"task() field `responseSchema` must be an object when provided\"\n            raise ValueError(msg)\n\n        return description, subagent_type, label, response_schema\n\n    async def _ainvoke_task_on_outer_loop(\n        self,\n        payload: dict[str, Any],\n        *,\n        state: _PTCState,\n    ) -> Any:\n        \"\"\"Validate JS `task()` input and invoke the runner on the right loop.","sourceCodeStart":540,"sourceCodeEnd":576,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/partners/quickjs/langchain_quickjs/_repl.py#L540-L576","documentation":"`_validate_task_payload` rejects a `label` field that is present but not a string. Unlike `description`/`subagentType`, `label` is optional (null is allowed), but if provided it must be a string; it is trimmed and an empty string is normalized to None. Raised as a ValueError before dispatch.","triggerScenarios":"JS calls `task({..., label: 42})` or passes a non-string value (number, boolean, object, array) for the optional `label` field.","commonSituations":"Model-generated JS putting an id/number in `label`, a marshaled non-string from a JS expression, or confusion between `label` semantics and the required fields.","solutions":["Remove the `label` field if it is not needed (it is optional)","Pass a non-empty string, e.g. `label: 'docs-search-1'`","Coerce to string in JS before calling: `label: String(myLabel)`"],"exampleFix":"// before\nawait task({ description: 'X', subagentType: 'researcher', label: 7 })\n// after\nawait task({ description: 'X', subagentType: 'researcher', label: 'run-7' })","handlingStrategy":"type-guard","validationCode":"if (payload.label !== undefined && typeof payload.label !== 'string') {\n  throw new Error('label must be a string');\n}","typeGuard":"function isValidLabel(v) {\n  return v === undefined || v === null || typeof v === 'string';\n}","tryCatchPattern":"try {\n  await task(payload);\n} catch (e) {\n  if (String(e).includes('label')) {\n    delete payload.label; // label is optional; drop invalid value\n    return await task(payload);\n  }\n  throw e;\n}","preventionTips":["Omit `label` entirely when not needed","Coerce values to string before assigning label","Never put numbers/ids directly in label without String()"],"tags":["validation","quickjs","task-bridge"],"backgroundTag":"schema-validation-failed","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}