Skip to content

The agent engineering platform.

Fix neo4j sanitize (#16439)

Tomaz Bratanicd0a808218838
diff --git a/libs/community/langchain_community/graphs/neo4j_graph.py b/libs/community/langchain_community/graphs/neo4j_graph.py
index 92efd27f08..b8970c06ec 100644
--- a/libs/community/langchain_community/graphs/neo4j_graph.py
+++ b/libs/community/langchain_community/graphs/neo4j_graph.py
@@ -160,7 +160,7 @@ class Neo4jGraph(GraphStore):
data = session.run(Query(text=query, timeout=self.timeout), params)
json_data = [r.data() for r in data]
if self.sanitize:
- json_data = value_sanitize(json_data)
+ json_data = [value_sanitize(el) for el in json_data]
return json_data
except CypherSyntaxError as e:
raise ValueError(f"Generated Cypher Statement is not valid\n{e}")
diff --git a/libs/community/tests/integration_tests/graphs/test_neo4j.py b/libs/community/tests/integration_tests/graphs/test_neo4j.py
index 948fe4c719..e4b47f907e 100644
--- a/libs/community/tests/integration_tests/graphs/test_neo4j.py
+++ b/libs/community/tests/integration_tests/graphs/test_neo4j.py
@@ -88,3 +88,31 @@ def test_neo4j_timeout() -> None:
e.code
== "Neo.ClientError.Transaction.TransactionTimedOutClientConfiguration"
)
+
+
+def test_neo4j_sanitize_values() -> None:
+ """Test that neo4j uses the timeout correctly."""
+ url = os.environ.get("NEO4J_URI")
+ username = os.environ.get("NEO4J_USERNAME")
+ password = os.environ.get("NEO4J_PASSWORD")
+ assert url is not None
+ assert username is not None
+ assert password is not None
+
+ graph = Neo4jGraph(url=url, username=username, password=password, sanitize=True)
+ # Delete all nodes in the graph
+ graph.query("MATCH (n) DETACH DELETE n")
+ # Create two nodes and a relationship
+ graph.query(
+ """
+ CREATE (la:LabelA {property_a: 'a'})
+ CREATE (lb:LabelB)
+ CREATE (lc:LabelC)
+ MERGE (la)-[:REL_TYPE]-> (lb)
+ MERGE (la)-[:REL_TYPE {rel_prop: 'abc'}]-> (lc)
+ """
+ )
+ graph.refresh_schema()
+
+ output = graph.query("RETURN range(0,130,1) AS result")
+ assert output == [{}]