SQL Tools¶
A suite of composable tools for text‑to‑SQL workflows and database insights. Use them end‑to‑end or pick individual blocks that fit your agent.
-
Relevant Table Schema Finder (LLM)
Selects the most relevant tables based on summaries and returns a schema context to guide query generation.
-
SQL Query Generator
Produces a single, syntactically valid T‑SQL query from a refined question and provided schema context.
-
SQL Executor
Executes the generated SQL with SQLAlchemy and returns rows as dictionaries for downstream formatting.
-
Final Answer Formatter
Converts raw rows into a clear, user‑friendly narrative and/or markdown table suitable for UI display.
-
DB Insights Tool
Answers conceptual questions about schema design and relationships using table metadata (no query execution).
Flow (typical)¶
- Relevant Table Schema Finder (LLM) → build focused schema context
- SQL Query Generator → produce a valid query
- SQL Executor → run the query and collect rows
- Final Answer Formatter → present the result to the user
(Use DB Insights Tool anytime you need architectural/relationship explanations.)
All SQL tools are standard
BaseToolsubclasses. Register them in aToolkit, validate inputs withToolSpec.check_inputs(), and chain state viaToolResponse.extras(e.g.,schema_context,db_results).