Commit ad0768a 1 parent f1cd112 commit ad0768a Copy full SHA for ad0768a
File tree 1 file changed +7
-4
lines changed
griptape/tools/sql_client
1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change 1
1
from __future__ import annotations
2
2
from typing import Optional
3
3
from attr import define , field
4
- from griptape .artifacts import InfoArtifact , ListArtifact
4
+ from griptape .artifacts import InfoArtifact , ListArtifact , ErrorArtifact
5
5
from griptape .tools import BaseTool
6
6
from griptape .utils .decorators import activity
7
7
from griptape .loaders import SqlLoader
@@ -38,9 +38,12 @@ def table_schema(self) -> str:
38
38
"schema" : Schema ({"sql_query" : str }),
39
39
}
40
40
)
41
- def execute_query (self , params : dict ) -> ListArtifact | InfoArtifact :
42
- query = params ["values" ]["sql_query" ]
43
- rows = self .sql_loader .load (query )
41
+ def execute_query (self , params : dict ) -> ListArtifact | InfoArtifact | ErrorArtifact :
42
+ try :
43
+ query = params ["values" ]["sql_query" ]
44
+ rows = self .sql_loader .load (query )
45
+ except Exception as e :
46
+ return ErrorArtifact (f"error executing query: { e } " )
44
47
45
48
if len (rows ) > 0 :
46
49
return ListArtifact (rows )
You can’t perform that action at this time.
0 commit comments