Sql analysis

From VectorSpaceLab/AREX-Skill · View interactive version

Sql analysis is an AI agent skill from the GitHub repository VectorSpaceLab/AREX-Skill. Operate ai-data-science-team SQL database querying, metadata inspection, read-only SQL safety, and SQLDatabaseAgent workflows.

How to use this skill

Skill file

SQL Analysis

Use this sub-skill when the task is to query a SQL database with ai-data-science-team, summarize database metadata, validate generated SQL for read-only safety, or operate SQLDatabaseAgent / make_sql_database_agent directly.

Route here for

Route away

Safe operating defaults

  1. Use a read-only database account or a disposable database copy whenever possible.
  2. Keep safe_mode=True unless the user explicitly accepts the risk and the database account itself is read-only.
  3. Start with n_samples=1 for metadata; increase only when sample values are necessary and safe to share.
  4. Do not launch Streamlit apps, call external LLM providers, download data, or write generated SQL logs unless the user asked for that side effect.
  5. Redact hostnames, database names, usernames, and connection URLs before sharing metadata or logs outside the local task.

Core workflow

import pandas as pd
import sqlalchemy as sql
from ai_data_science_team.agents import SQLDatabaseAgent

engine = sql.create_engine("sqlite:///example.db")
llm = ...  # caller-provided LangChain-compatible chat model

agent = SQLDatabaseAgent(
    model=llm,
    connection=engine,
    n_samples=1,
    safe_mode=True,
    log=False,
    bypass_recommended_steps=True,
    bypass_explain_code=True,
)
agent.invoke_agent("Return sales by month for 2024", max_retries=3, retry_count=0)

query = agent.get_sql_query_code()
data = agent.get_data_sql()
frame = pd.DataFrame(data) if isinstance(data, dict) else data
error = agent.get_response().get("sql_database_error") if agent.get_response() else None

If the user only needs schema understanding, avoid LLM calls and use get_database_metadata as shown in workflows.

References and bundled checks

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.