{"record":{"id":"fcb957ee45bf4814","repo":"langchain-ai/deepagents","slug":"context-auto-approve-must-be-a-boolean-or-null-go","errorCode":null,"errorMessage":"context.auto_approve must be a boolean or null, got {type(auto_approve).__name__}.","messagePattern":"context\\.auto_approve must be a boolean or null, got (.+?)\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/offload_api.py","lineNumber":481,"sourceCode":"        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 (\n        not isinstance(events, list)\n        or any(not isinstance(event, str) for event in events)\n    ):\n        msg = \"context.hooks_server_events must be a list of strings or null.\"\n        raise TypeError(msg)\n\n\ndef _checkpoint_id(state: Mapping[str, object]) -> str:\n    checkpoint = state.get(\"checkpoint\")\n    value = checkpoint.get(\"checkpoint_id\") if isinstance(checkpoint, Mapping) else None\n    if not isinstance(value, str) or not value:\n        msg = \"The thread has no checkpoint to offload.\"\n        raise _OffloadConflictError(msg)\n    return value\n\n","sourceCodeStart":463,"sourceCodeEnd":499,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/offload_api.py#L463-L499","documentation":"`context.auto_approve` controls whether offload operations are auto-approved and must be strictly a bool or null. Passing a truthy value like \"true\", 1, or \"yes\" is rejected because the SDK does not coerce — silent coercion of config strings is a common source of misconfiguration. The check runs inside _validate_context during payload preparation.","triggerScenarios":"Calling offload() with context={'auto_approve': 'true'}, {'auto_approve': 1}, {'auto_approve': 'yes'}, or any non-bool object; JSON configs where auto_approve was serialized as a string.","commonSituations":"YAML/JSON config files that quote booleans (auto_approve: \"true\"), environment variables (all env vars are strings), older configs written before strict typing was enforced, or frontend forms sending 'on'/'off' strings.","solutions":["Coerce deliberately: auto_approve = str(value).lower() in ('1','true','yes') before building context.","If loaded from env, map {'true','1','yes'} -> True, {'false','0','no'} -> False, missing -> None.","Remove the key or pass None when auto-approval behavior is not being configured.","Audit your config source so the field is serialized as a real JSON boolean, not a string."],"exampleFix":"// before\ncontext = {\"auto_approve\": os.environ.get(\"AUTO_APPROVE\", \"true\")}\n// after\nraw = os.environ.get(\"AUTO_APPROVE\")\ncontext = {\"auto_approve\": raw.lower() in (\"1\", \"true\", \"yes\") if raw is not None else None}","handlingStrategy":"validation","validationCode":"def validate_auto_approve(value):\n    return value is None or isinstance(value, bool)\n# call before offload: assert validate_auto_approve(ctx.get(\"auto_approve\"))","typeGuard":"def is_bool_or_none(value) -> bool:\n    return value is None or isinstance(value, bool)","tryCatchPattern":"try:\n    state = await offload(thread_id, payload)\nexcept TypeError as exc:\n    if \"auto_approve\" in str(exc):\n        raw = payload[\"context\"].get(\"auto_approve\")\n        payload[\"context\"][\"auto_approve\"] = str(raw).lower() in (\"1\", \"true\", \"yes\")\n        state = await offload(thread_id, payload)\n    else:\n        raise","preventionTips":["Serialize config booleans as real JSON/YAML booleans, never quoted strings","Centralize env-var-to-bool parsing in one helper","Do not conflate truthiness (1, 'yes') with the bool type the API requires","Omit the key when the setting is unconfigured"],"tags":["type-error","validation","python","config"],"backgroundTag":"type-validation-failed","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}