Database Agent
The Database Agent connects to relational databases like PostgreSQL, MySQL, and MariaDB. It is ideal for structured data analysis, metrics, and reporting — allowing users to ask natural language questions that get translated into SQL queries.
Steps to Create
Section titled “Steps to Create”-
Click on Agent in the left sidebar, then give your agent a name.
-
Select Database Agent from the Agent Type list and click Next.
-
Connect your database: Enter the connection details —
- Database Type: PostgreSQL, MySQL, or MariaDB
- Host and Port
- Database Name
- Username and Password
-
Click Test Connection to verify connectivity.
-
Schema Configuration: Once connected, the system fetches your database schema (DDL).
- Select the tables you want the agent to have access to.
- Review and enrich table/column descriptions — clear descriptions help the agent generate more accurate SQL.
-
Domain Knowledge (optional): Add domain-specific context to help the agent understand your business logic (e.g., “revenue is calculated as quantity × unit_price”).
-
Review the auto-generated agent description and click Create Agent.
How It Works
Section titled “How It Works”When a user submits a question, the Database Agent follows this pipeline:
User Input → Security Check → Question Rewrite → [DDL + Business Logic + Few-shot Examples] → Generate SQL →Ambiguity Detection → [Clear] → Execute Query → Generate Answer [Ambiguous] → Request ClarificationKey Components
Section titled “Key Components”Security Check
- Detects malicious inputs such as SQL injection, tautologies, and schema enumeration attempts.
- Returns a safe error message for unsafe queries before any processing occurs.
Question Rewriting
- Converts relative dates to absolute dates (e.g., “last 30 days” → actual date range).
- Incorporates follow-up context for multi-turn conversations.
Knowledge Retrieval
- DDL: Database schema definitions used to generate accurate SQL.
- Business Logic: Domain knowledge that guides query interpretation.
- Few-shot Examples: Sample question–SQL pairs that improve generation quality.
SQL Generation
- Uses chain-of-thought reasoning before producing a query.
- Detects ambiguity and asks for clarification when the question is unclear.
- Auto-retries and repairs queries on execution failure.
Run and Test
Section titled “Run and Test”-
Click Run to start the agent.
-
Enter a test question.
-
The agent will generate and execute the appropriate SQL query and return the results.
Debug with Step Run
Section titled “Debug with Step Run”Discover supports step-by-step execution for agent components, providing a robust debugging mechanism:
-
Click the triangle icon above a component, or open the component’s detail page and select Test Run.
-
Enter a test question and click Run to see the component’s output.
-
Adjust Rerank model, Similarity threshold, or Keyword similarity weight if retrieval results are not as expected.
-
Observe the inputs and outputs of each node to identify where issues occur.
Production Considerations
Section titled “Production Considerations”- Schema descriptions: Provide clear, accurate descriptions for tables and columns — this directly impacts SQL quality.
- Business logic: Document domain-specific rules (e.g., metric definitions, filters that always apply) in the Domain Knowledge section.
- Few-shot examples: High-quality question–SQL pairs significantly improve the agent’s accuracy on complex queries.
- Security: The agent automatically blocks destructive operations (
DELETE,DROP,TRUNCATE). Ensure your database user has read-only permissions as an additional safeguard. - Synonyms and abbreviations: If your users commonly use shorthand or domain-specific terms, add a thesaurus or synonym mappings to your Domain Knowledge to help the agent interpret them correctly.