AshenH commited on
Commit
a325dbc
·
verified ·
1 Parent(s): d849dc0

Update tools/sql_tool.py

Browse files
Files changed (1) hide show
  1. tools/sql_tool.py +6 -4
tools/sql_tool.py CHANGED
@@ -63,10 +63,10 @@ def run_duckdb_query(query: str) -> str:
63
  conn.close()
64
 
65
  @tool
66
- def get_table_schema(table_name: str = "positions") -> str:
67
  """
68
  Returns the schema (column names and data types) for the specified table in the MotherDuck database.
69
- Defaults to the 'positions' table.
70
  """
71
  conn = None
72
  try:
@@ -78,7 +78,9 @@ def get_table_schema(table_name: str = "positions") -> str:
78
  schema_df = conn.execute(query).fetchdf()
79
 
80
  if schema_df.empty:
81
- return f"Error: Table '{table_name}' not found in the MotherDuck database. Available tables: {conn.execute('SHOW TABLES;').fetchnames()}"
 
 
82
 
83
  # Format the schema into a simple string: name TYPE, name TYPE, ...
84
  schema_parts = [f"{row['name']} {row['type']}" for index, row in schema_df.iterrows()]
@@ -90,4 +92,4 @@ def get_table_schema(table_name: str = "positions") -> str:
90
  return f"DuckDB Schema Error: {e}"
91
  finally:
92
  if conn:
93
- conn.close()
 
63
  conn.close()
64
 
65
  @tool
66
+ def get_table_schema(table_name: str = "my_db.main.masterdataset_v") -> str:
67
  """
68
  Returns the schema (column names and data types) for the specified table in the MotherDuck database.
69
+ Defaults to the 'my_db.main.masterdataset_v' table.
70
  """
71
  conn = None
72
  try:
 
78
  schema_df = conn.execute(query).fetchdf()
79
 
80
  if schema_df.empty:
81
+ # Also fetch available table names for better error reporting
82
+ available_tables = conn.execute('SHOW TABLES;').fetchnames()
83
+ return f"Error: Table '{table_name}' not found. Available tables: {available_tables}"
84
 
85
  # Format the schema into a simple string: name TYPE, name TYPE, ...
86
  schema_parts = [f"{row['name']} {row['type']}" for index, row in schema_df.iterrows()]
 
92
  return f"DuckDB Schema Error: {e}"
93
  finally:
94
  if conn:
95
+ conn.close()