diff --git a/graphrag_sdk/entity.py b/graphrag_sdk/entity.py index 291ed06..a82c9ce 100644 --- a/graphrag_sdk/entity.py +++ b/graphrag_sdk/entity.py @@ -144,7 +144,9 @@ def to_graph_query(self) -> str: [str(attr) for attr in self.attributes if not attr.unique] ) if self.description: - non_unique_attributes += f"{', ' if len(non_unique_attributes) > 0 else ''} {descriptionKey}: '{self.description}'" + # Escape special characters to prevent Cypher syntax errors + escaped_description = self.description.replace("\\", "\\\\").replace("'", "\\'").replace('"', '\\"') + non_unique_attributes += f"{', ' if len(non_unique_attributes) > 0 else ''} {descriptionKey}: '{escaped_description}'" return f"MERGE (n:{self.label} {{{unique_attributes}}}) SET n += {{{non_unique_attributes}}} RETURN n" def __str__(self) -> str: