SQL Connector
Key Concepts
The SQL Connector block allows seamless integration between your SQL database and an LLM-powered workflow in INTELLITHING. It is designed to be:
- Robust: Capable of handling large-scale and complex database systems.
- Scalable: Supports high-volume query handling.
- Secure: Includes built-in mechanisms to detect and prevent prompt injection attacks.
- Reliable: Features multiple evaluation and correction layers for accurate data retrieval.
Key Definitions
Term | Definition |
---|---|
SQL Connector | A block in INTELLITHING that enables secure, intelligent access to SQL databases. |
LLM | Large Language Model that generates and interprets natural language queries. |
Database Configuration | The set of credentials and metadata used to establish a connection to a SQL database. |
Workflow Node | A stage in the workflow pipeline that performs a specific action, such as initializing or executing queries. |
Setup Guide: Configuring a New SQL Connection
Follow the steps below to connect a SQL database to INTELLITHING:
1. DB Type
- Choose the database type (e.g., MySQL, PostgreSQL) from the dropdown list.
- This selection determines the database driver and connection method.
2. DB Host
- Enter the host address of your database.
Example:127.0.0.1
ordatabase.example.com
3. DB Port
- Provide the port used by your database:
- MySQL:
3306
- PostgreSQL:
5432
4. DB Name
- Specify the name of the target database.
- Ensure the database exists and contains the relevant tables.
5. DB User
- Input the username with permission to access the necessary tables.
6. DB Password
- Enter the corresponding password for the DB user.
- Use the eye icon to toggle visibility if needed.
7. DB Table
- Enter the name(s) of the table(s) you want to access.
- Click Add to DB Tables to include the table in your configuration.
- This helps scope access to only necessary data—important for large databases.
8. Description
-
Provide a description for the router engine to contextualize this connection.
Example: Database of sales data. Used to answer queries related to sales. -
Optional in custom workflows but recommended for maintainability.
9. Save
- Click Save to store your configuration and return to the main editor pane.
Workflow Nodes
The SQL Connector block includes a sequence of nodes for processing SQL queries. Each node contributes to secure and structured interaction with your database.
Node Descriptions
initialize_workflow
(First Node)
- Initializes the environment, resources, and configurations required to begin workflow execution.
index_all_tables
- Scans and indexes all defined tables in the connected database.
- Organizes data for efficient retrieval and future operations.
prepare_table_retrieval
- Analyzes the database schema to prepare for targeted table retrieval.
get_vector_index_dict
- Generates a vectorized index dictionary from the tables for similarity-based or semantic query matching.
retrieve_table_context
- Retrieves relevant context from the selected table(s) based on the user query or workflow need.
generate_sql_prompt
- Constructs a database-aware prompt to guide the LLM in generating valid SQL queries.
parse_sql_from_response
- Parses and validates the SQL query returned by the LLM to ensure safe and executable syntax.
setup_sql_retriever
- Configures the connection for executing the SQL query on the specified database.
execute_sql_and_generate_response
(Last Node)
- Executes the SQL query and processes the results.
- Outputs a structured response for downstream blocks or for direct return to the user.
Best Practices for Successful SQL Integration
- Verify credentials: Double-check database hostname, port, user, and password.
- Test before use: After saving, test the connection to ensure proper configuration.
- Use descriptions: Helps differentiate between multiple connections, especially with the default router.
- Firewall considerations: If your database is behind a firewall, you can activate a proxy for your database under security tab.
Example Use Case
To integrate a customer data warehouse for analytics:
- Configure connection to
customer_db
with tableuser_activity
. - Use
generate_sql_prompt
to interpret natural language questions like "Show top users last month." - Parse and execute the query with
parse_sql_from_response
andexecute_sql_and_generate_response
. - Return results to the user via an LLM or connected application interface.