langchain-spicedb package provides LangChain tools that enable agents to check SpiceDB permissions before taking actions. These tools are particularly useful for building agentic RAG systems where the agent needs to verify access permissions before retrieving or operating on resources.
Installation
Setup
Environment setup
Tools
SpiceDBPermissionTool
Check if a single user has permission to access a specific resource.Initialization
Parameters
- spicedb_endpoint (str): SpiceDB server address (default: “localhost:50051”)
- spicedb_token (str): Pre-shared key for SpiceDB authentication
- resource_type (str): SpiceDB resource type (e.g., “document”, “article”)
- subject_type (str): SpiceDB subject type (default: “user”)
- fail_open (bool): If True, allow access on errors; if False, deny on errors (default: False)
- use_tls (bool): Whether to use TLS for SpiceDB connection (default: False)
Usage with agents
Direct tool usage
SpiceDBBulkPermissionTool
Check permissions for multiple resources at once - useful when an agent needs to verify access to several documents before proceeding.Initialization
Parameters
Same asSpiceDBPermissionTool (see above).
Usage with agents
Direct tool usage
How agents decide to call these tools
Agents use the tool name and description to decide when to invoke them:Tool names
check_spicedb_permission- Single permission checkcheck_spicedb_bulk_permissions- Bulk permission check
Tool descriptions
Both tools have detailed descriptions that guide the agent:- When to use: “Use this tool before retrieving sensitive documents or taking actions that require authorization”
- What it does: Checks if a user has permission to access a resource
- What it returns: “true”/“false” or list of accessible resources
Influencing tool usage
To make agents more likely to check permissions:-
System Prompt: Include explicit security guidance
-
Lower Temperature: Use temperature=0 for more deterministic behavior
-
Clear system prompts: Provide explicit instructions for tool usage
- Few-Shot Examples: Include examples in the prompt showing the tool being used
Input Schema
SpiceDBPermissionTool
SpiceDBBulkPermissionTool
Error handling
Fail closed (default)
By default, tools fail closed - if there’s an error checking permissions, access is denied:Fail open
For development or specific use cases:Complete example: Secure document agent
API reference
SpiceDBPermissionTool
- name:
"check_spicedb_permission" - description: Checks if a user has permission to access a resource
- args_schema:
SpiceDBPermissionInput - return_type:
str(“true” or “false”)
SpiceDBBulkPermissionTool
- name:
"check_spicedb_bulk_permissions" - description: Checks if a user has permission to access multiple resources
- args_schema:
SpiceDBBulkPermissionInput - return_type:
str(comma-separated list of accessible resources or denial message)
Related components
Connect these docs to Claude, VSCode, and more via MCP for real-time answers.

