How can i filter the Neo4jGraph Object?

I am working with the Neo4jGraph object and passing it to the GraphCypherQAChain . However, I want to restrict access to specific parts of the graph, such as only allowing certain node labels (e.g. ,Person , Company ) and certain relationship types (e.g., WORKS_AT ).

This is what i am using
from langchain_community.graphs import Neo4jGraph

graph.refresh_schema()
print(graph.schema)

chain = GraphCypherQAChain.from_llm(graph=graph,
cypher_llm = cypher_model,
qa_llm= qa_model,
verbose=True,
validate_cypher = True,
allow_dangerous_requests=True
#use_function_response = True
)

This Neo4jGraph Object is returning all the Nodes and Relationships present in the DB. But i want to apply filter on this object so i can access only specific node or relationship. Is there any way to do it?

Any help would be really Appreciated!

If security isn't the issue - you can build the queries with the labels and dynamically filter the results.

If security is the issue:

  • You'll need to use RBAC
  • If you want the same caller to retrieve results depending on the permissions or associations of the user - that's not easily solvable with RBAC.
1 Like