diff --git a/dbgpt/datasource/conn_tugraph.py b/dbgpt/datasource/conn_tugraph.py index debbc74ca..3557ac9e9 100644 --- a/dbgpt/datasource/conn_tugraph.py +++ b/dbgpt/datasource/conn_tugraph.py @@ -1,6 +1,6 @@ """TuGraph Connector.""" -import json +import json, re from typing import Dict, List, cast, Union, Generator from .base import BaseConnector @@ -23,6 +23,10 @@ def __init__(self, driver, graph): def create_graph(self, graph_name: str) -> None: """Create a new graph.""" # run the query to get vertex labels + + if not re.match(r"^[a-zA-Z\u4e00-\u9fff]", graph_name): + raise ValueError("Graph name must start with a letter or Chinese character, and cannot begin with a number or special character.") + with self._driver.session(database="default") as session: graph_list = session.run("CALL dbms.graph.listGraphs()").data() exists = any(item["graph_name"] == graph_name for item in graph_list)