{"record":{"id":"ddea1d3cdaac08d8","repo":"langchain-ai/deepagents","slug":"backend-route-prefix-r-got-type-backend-name","errorCode":null,"errorMessage":"Backend route {prefix!r} got {type(backend).__name__}, which is not a BackendProtocol","messagePattern":"Backend route (.+?) got (.+?), which is not a BackendProtocol","errorType":"validation","errorClass":"ExtensionError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/extensions/api.py","lineNumber":172,"sourceCode":"\n        Raises:\n            ExtensionError: If the prefix or backend is invalid.\n        \"\"\"\n        self._ensure_active()\n        from deepagents.backends.protocol import BackendProtocol\n\n        if _ROUTE_PREFIX.fullmatch(prefix) is None:\n            msg = (\n                f\"Invalid backend route prefix {prefix!r}: use lowercase path \"\n                \"segments and include leading and trailing slashes\"\n            )\n            raise ExtensionError(msg)\n        if not isinstance(backend, BackendProtocol):\n            msg = (\n                f\"Backend route {prefix!r} got {type(backend).__name__}, \"\n                \"which is not a BackendProtocol\"\n            )\n            raise ExtensionError(msg)\n        self._registry.add_backend_route(prefix, backend, self._source)\n\n    def on_shutdown(self, hook: Callable[[], Any]) -> None:\n        \"\"\"Register a deterministic session teardown callback.\n\n        Args:\n            hook: Sync or async zero-argument callback.\n\n        Raises:\n            ExtensionError: If `hook` is not callable.\n        \"\"\"\n        self._ensure_active()\n        if not callable(hook):\n            msg = \"Shutdown hook is not callable\"\n            raise ExtensionError(msg)\n        self._registry.add_shutdown_hook(hook, self._source)\n","sourceCodeStart":154,"sourceCodeEnd":189,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/extensions/api.py#L154-L189","documentation":"Raised by ExtensionApi.register_backend_route when the backend argument is not an instance of BackendProtocol. The library type-checks the mounted object before adding the route to the registry.","triggerScenarios":"Calling `ext.register_backend_route('/prefix/', obj)` where obj is a raw function, a class (not an instance), a wrapper, or any object that does not satisfy the BackendProtocol interface.","commonSituations":"Passing the backend class instead of an instance; passing a custom object that implements the methods duck-typed but is not registered/checked as BackendProtocol; refactors that renamed or replaced the backend object.","solutions":["Pass an actual backend instance implementing BackendProtocol, e.g. a FilesystemBackend-like object","If you passed the class, instantiate it: register_backend_route('/p/', MyBackend())","If using a custom backend, make sure it structurally satisfies BackendProtocol (or subclasses/registers as one)","Check the traceback's type name in the message to confirm what object was actually passed"],"exampleFix":"// before\next.register_backend_route(\"/data/\", FilesystemBackend)\n\n// after\next.register_backend_route(\"/data/\", FilesystemBackend(root=\"/data\"))","handlingStrategy":"type-guard","validationCode":"if not isinstance(backend, BackendProtocol):\n    raise TypeError(\"register_backend_route requires a BackendProtocol instance\")","typeGuard":"def is_backend(obj: object) -> bool:\n    return isinstance(obj, BackendProtocol)","tryCatchPattern":"try:\n    ext.register_backend_route(prefix, backend)\nexcept ExtensionError as exc:\n    logger.error(\"%r is not a BackendProtocol: %s\", type(backend).__name__, exc)","preventionTips":["Instantiate backend classes before mounting them","Run mypy/pyright so non-protocol backends fail type checking","Keep a single factory function that constructs protocol-compliant backends"],"tags":["extensions","backend-route","type-check"],"backgroundTag":"wrong-argument-type","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}