{"record":{"id":"e28f47ced299d5cd","repo":"langchain-ai/deepagents","slug":"context-key-must-be-an-object-got-type-value","errorCode":null,"errorMessage":"context.{key} must be an object, got {type(value).__name__}.","messagePattern":"context\\.(.+?) must be an object, got (.+?)\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/offload_api.py","lineNumber":465,"sourceCode":"    Only the listed keys are type-checked; unknown keys pass through so a\n    newer client can keep talking to this server version.\n\n    Args:\n        context: The request's `context` object.\n\n    Raises:\n        TypeError: If a consumed field has the wrong type, naming the field.\n    \"\"\"\n    for key in _CONTEXT_STR_OR_NONE_FIELDS:\n        value = context.get(key)\n        if value is not None and not isinstance(value, str):\n            msg = f\"context.{key} must be a string or null, got {type(value).__name__}.\"\n            raise TypeError(msg)\n    for key in _CONTEXT_DICT_FIELDS:\n        value = context.get(key)\n        if value is not None and not isinstance(value, dict):\n            msg = f\"context.{key} must be an object, got {type(value).__name__}.\"\n            raise TypeError(msg)\n    limit = context.get(\"model_context_limit\")\n    # bool is an int subclass, so exclude it explicitly: JSON `true` is not a\n    # token limit.\n    if limit is not None and (isinstance(limit, bool) or not isinstance(limit, int)):\n        msg = (\n            \"context.model_context_limit must be an integer or null, \"\n            f\"got {type(limit).__name__}.\"\n        )\n        raise TypeError(msg)\n    auto_approve = context.get(\"auto_approve\")\n    if auto_approve is not None and not isinstance(auto_approve, bool):\n        msg = (\n            f\"context.auto_approve must be a boolean or null, \"\n            f\"got {type(auto_approve).__name__}.\"\n        )\n        raise TypeError(msg)\n    events = context.get(\"hooks_server_events\")\n    if events is not None and (","sourceCodeStart":447,"sourceCodeEnd":483,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/offload_api.py#L447-L483","documentation":"`_validate_context` enforces that each field in `_CONTEXT_DICT_FIELDS` is either an object (dict) or null. Any other type raises a `TypeError` naming `context.<key>` and the received type, since these context fields hold nested JSON objects.","triggerScenarios":"Calling an offload API operation with a dict-typed context field set to a string, list, or number, e.g. `context={\"metadata\": \"[]\"}` or a JSON-encoded string passed instead of the parsed object.","commonSituations":"Passing a JSON string that was never `json.loads`-ed into a dict; config files where a nested object was flattened to a string; lists supplied where mappings are required.","solutions":["Pass an actual dict: `json.loads(raw)` instead of the raw JSON string","Null the field out if no nested data is needed","Validate the context structure before invoking the API"],"exampleFix":"// before\ncontext = {\"metadata\": '{\"run\": \"abc\"}'}\n// after\nimport json\ncontext = {\"metadata\": json.loads('{\"run\": \"abc\"}')}","handlingStrategy":"validation","validationCode":"for k in context_dict_fields:\n    v = context.get(k)\n    if v is not None and not isinstance(v, dict):\n        raise TypeError(f\"context.{k} must be an object\")","typeGuard":"def is_dict_or_none(v: object) -> TypeGuard[dict | None]:\n    return v is None or isinstance(v, dict)","tryCatchPattern":"try:\n    payload = _operation_payload(op, context)\nexcept TypeError as e:\n    logging.error(\"invalid context: %s\", e)\n    raise","preventionTips":["Parse JSON strings with json.loads before placing them in context","Validate nested context objects before API calls","Never pass JSON-encoded strings where objects are expected"],"tags":["python","validation","type-error","context","offload"],"backgroundTag":"schema-validation-failed","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}