From 97ec7a61ed2c4bc51dc1d7409cadd5001d34794c Mon Sep 17 00:00:00 2001 From: Abhinv Singh Parmar Date: Mon, 17 Nov 2025 19:36:48 +0530 Subject: [PATCH] fix: escape special characters in entity descriptions for Cypher queries Prevents syntax errors when descriptions contain quotes or backslashes. The escaping only affects query generation stored data remains unchanged --- graphrag_sdk/entity.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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: