{"record":{"id":"ee2368575515025b","repo":"langchain-ai/deepagents","slug":"workspace-configuration-must-be-json-serializable","errorCode":null,"errorMessage":"workspace configuration must be JSON serializable","messagePattern":"workspace configuration must be JSON serializable","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/workspace.py","lineNumber":113,"sourceCode":"\n\ndef canonical_workspace_config(value: object | None) -> tuple[str, str]:\n    \"\"\"Return bounded canonical JSON and its SHA-256 fingerprint.\n\n    Raises:\n        TypeError: If the configuration is not an object.\n        ValueError: If it cannot be serialized or exceeds the size limit.\n    \"\"\"\n    if value is None:\n        value = {}\n    if not isinstance(value, dict):\n        msg = \"workspace_config must be an object\"\n        raise TypeError(msg)\n    try:\n        serialized = json.dumps(value, sort_keys=True, separators=(\",\", \":\"))\n    except (TypeError, ValueError) as exc:\n        msg = \"workspace configuration must be JSON serializable\"\n        raise ValueError(msg) from exc\n    if len(serialized) > _MAX_CONFIG_LENGTH:\n        msg = \"workspace configuration is too large\"\n        raise ValueError(msg)\n    return serialized, hashlib.sha256(serialized.encode()).hexdigest()\n\n\ndef _fingerprint(value: object) -> str:\n    serialized = json.dumps(value, sort_keys=True, separators=(\",\", \":\"))\n    return hashlib.sha256(serialized.encode()).hexdigest()\n\n\ndef resolve_workspace(\n    cwd: object,\n    workspace_config: object | None = None,\n    *,\n    config_fingerprint: str | None = None,\n) -> WorkspaceBinding:\n    \"\"\"Resolve and validate a client workspace claim.","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/workspace.py#L95-L131","documentation":"`canonical_workspace_config` JSON-serializes the config to produce a canonical fingerprint. This ValueError is raised when the config dict contains values that cannot be JSON-serialized (e.g. sets, datetime objects, custom class instances, non-string dict keys that cannot convert), so no stable fingerprint can be computed.","triggerScenarios":"Calling `canonical_workspace_config`, `bind_thread_workspace`, `resolve_workspace`, or `require_thread_workspace` with a dict containing unserializable values such as `set()`, `datetime.now()`, path objects, or a key of an unsupported type.","commonSituations":"Passing `Path` objects or datetimes parsed from CLI args in the config; using sets for allowed paths; dict keys that are ints or tuples; configs built from in-memory objects rather than JSON-loaded data.","solutions":["Convert unserializable values to JSON-native types (str for Path/datetime, list for set) before passing","Use `json.dumps(workspace_config)` in a pre-check to find the offending value","Ensure all dict keys are strings"],"exampleFix":"// before\ncfg = {\"deadline\": datetime.now(), \"roots\": {Path(\"/tmp\")}}\n// after\ncfg = {\"deadline\": datetime.now().isoformat(), \"roots\": [str(p) for p in roots]}","handlingStrategy":"validation","validationCode":"try:\n    json.dumps(workspace_config, sort_keys=True)\nexcept (TypeError, ValueError) as exc:\n    raise ValueError(f\"workspace_config not JSON serializable: {exc}\") from exc","typeGuard":null,"tryCatchPattern":"try:\n    bind_thread_workspace(tid, cwd, workspace_config=cfg)\nexcept ValueError as exc:\n    if \"JSON serializable\" in str(exc):\n        cfg = json.loads(json.dumps(cfg, default=str))\n        bind_thread_workspace(tid, cwd, workspace_config=cfg)","preventionTips":["Convert Path/datetime/set values to str/list before building config","Keep configs JSON-round-trippable","Test `json.dumps(cfg)` in config-loading code"],"tags":["workspace","json","serialization","validation"],"backgroundTag":"config-not-json-serializable","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}