Open
Description
When initializing langchain_neo4j.graphs.Neo4jGraph with enhance_schema=True, a neo4j.exceptions.CypherSyntaxError: {code: Neo.ClientError.Statement.SyntaxError} {message: Variable RETURN not defined ... "RETURN {} AS output"} occurs. This error appears during the schema introspection process, specifically when the Neo4j graph contains relationships with properties of boolean type.
Steps to Reproduce:
- Populate a Neo4j database with a graph schema that includes at least one relationship type having a property of boolean type.
Example: A relationship (:Fabric)-[r:HAS_COLOR]->(:Color) where r has a property IsMasterColor which is set to Cypher true or false.
2.In Python, attempt to initialize Neo4jGraph pointing to this database with enhance_schema=True:
from langchain_neo4j.graphs import Neo4jGraph
graph = Neo4jGraph(
url="bolt://localhost:7687",
username="neo4j",
password="your_password",
enhance_schema=True # Problem occurs with True
)
- The initialization fails with the CypherSyntaxError.
File ".../langchain_neo4j/graphs/neo4j_graph.py", line 278, in refresh_schema
self.structured_schema = get_structured_schema(
^^^^^^^^^^^^^^^^^^^^^^
File ".../neo4j_graphrag/schema.py", line 356, in get_structured_schema
enhance_schema(
File ".../neo4j_graphrag/schema.py", line 903, in enhance_schema
enhance_properties(
File ".../neo4j_graphrag/schema.py", line 836, in enhance_properties
enhanced_info = query_database(
File ".../neo4j_graphrag/schema.py", line 164, in query_database
data = driver.execute_query(
...
neo4j.exceptions.CypherSyntaxError: {code: Neo.ClientError.Statement.SyntaxError} {message: Variable `RETURN` not defined (line 3, column 1 (offset: 50))
"RETURN {} AS output"
^}
- The error does not occur if the boolean property (e.g., IsMasterColor) is removed from the relationships in the database.
- The error does not occur if Neo4jGraph is initialized with enhance_schema=False.
- The boolean property itself is correctly stored and typed as boolean in Neo4j when created.
- The issue seems to stem from how neo4j_graphrag.schema.enhance_properties (or a function it calls) constructs its Cypher queries for schema introspection when encountering boolean relationship properties, leading to the malformed RETURN {} AS output query.
Metadata
Metadata
Assignees
Labels
No labels