This topic describes how to use LangStudio to create an intelligent SQL generation assistant application flow. This application flow retrieves basic information about database tables, passes user questions and the table information to a large language model (LLM) to generate SQL statements, and then executes the statements to return query results. This template supports Alibaba Cloud RDS for MySQL. You can adapt this template for your specific use cases.
Background information
In modern data-driven environments, the ability to quickly and accurately extract information from databases is crucial for many applications. The intelligent SQL generation assistant application flow combines natural language processing (NLP) with database query capabilities to provide an efficient and intelligent solution. By integrating with Alibaba Cloud RDS for MySQL, this application flow retrieves a database table's basic information when a user asks a question. It then uses an LLM to generate the corresponding SQL query, which is executed by a Python node to return the query result. This integration improves data query accuracy and the handling of complex queries. It also lets users interact with the database using natural language, improving data retrieval efficiency and decision-making. You can adapt this template in LangStudio for specialized applications in fields such as finance, education, and healthcare that require rapid data queries.
Prerequisites
The intelligent SQL generation assistant application flow supports Alibaba Cloud RDS for MySQL. You must first create a database. For more information, see the ApsaraDB RDS User Guide.
1. (Optional) Deploy an LLM
The intelligent SQL generation assistant application flow requires an LLM service. If you have a compatible model service that supports the OpenAI API, you can skip this step and use your existing service. This guide uses the DeepSeek-R1 model as an example. You can go to QuickStart > Model Gallery to deploy the model. For more information about deployment, see One-click deployment of DeepSeek-V3 and DeepSeek-R2 and Model deployment and training.

2. Create connections
2.1 Create an LLM service connection
The LLM service connection in this guide is based on the model service deployed in QuickStart > Model Gallery, which is an Elastic Algorithm Service (EAS) service. For more information about other types of connections, see Connection configuration.
Go to LangStudio, select a workspace, and click Enter LangStudio. On the Connection > Model Service tab, click New Connection to create a General LLM Service connection.

The following table describes the key parameters.
Parameter | Description |
Name | After deploying a model from Model Gallery, find its name on the model details page. You can access this page by clicking the model card in the Model Gallery page. For more information, see Create a connection-Model service. |
Service Provider |
|
2.2 Create a database connection
On the Connection > Database tab, click New Connection to create an ApsaraDB RDS for MySQL connection.

The following table describes the key parameters.
Parameter | Description |
host/port | To obtain the host (internal endpoint) and port (internal port), see View and manage instance endpoints and ports. |
database | The database name configured when you create a database. |
username/password | The account and password configured when you create a database account. |
3. Create and run an application flow
Go to LangStudio, select a workspace, and click Enter LangStudio. Then, on the Application Flow tab, click Create Application Flow to create an intelligent SQL generation assistant application flow.

Start the runtime: Click Select Runtime and select an existing runtime from the drop-down list. If no runtime is available, you can create one on the Runtime tab of the LangStudio page. Note: For VPC, select the VPC used to create the RDS for MySQL instance. Alternatively, ensure the selected VPC is connected to the RDS instance's VPC.
ImportantEnsure the runtime is started before you parse Python nodes or view more tools.
Develop the application flow.

You can keep the default settings for other configurations or customize them as needed. The key nodes are configured as follows:
Get Table Creation DDL: Obtains and generates basic information about database tables (DDL statements).
connection_name: Enter the name of the connection that you created in the 2.2 Create a database connection step. Ensure the entered name exactly matches the name of the created connection.
LLM node: To generate SQL code, this node passes the user's question and the database table information from the DDL node to the LLM.
Model Configuration: Select the connection that you created in the 2.1 Create an LLM service connection step.
Chat History: Specifies whether to enable chat history. If you enable this feature, the historical conversation information is used as an input variable.
Execute SQL: Executes the SQL statements returned by the LLM and returns the query results.
connection_name: Enter the name of the connection that you created in the 2.2 Create a database connection step. Make sure the name you enter is identical to the one you created.
For more information about each node component, see Appendix: Description of built-in components.
Debug/Run: Click Run in the upper-right corner to start the application flow. For more information about common runtime issues for the application flow, see FAQ.

View the trace. Click View Trace below the generated answer to view trace details or the topology.

4. Deploy the application flow
To deploy the application flow as an EAS service, click Deploy in the upper-right corner of the application flow development page. Keep the default settings for the other deployment parameters or configure them based on your business requirements. The key parameters are configured as follows:
Resource Information > Instances: Configure the number of service instances. The deployment in this topic is for testing purposes only, so the number of instances is set to 1. In a production environment, we recommend configuring multiple instances to avoid single points of failure.
VPC > VPC configuration: Select the VPC where the RDS for MySQL instance is located, or make sure that the selected VPC is connected to the VPC of the RDS for MySQL instance.
For more information about deployment, see Application flow deployment.
5. Call the service
After the service is deployed, you are redirected to the PAI-EAS console. On the Online Debugging tab, configure and send a request. The key in the request body must match the Chat Input field in the Start Node of the application flow. In this topic, the default field is question.

For other call methods, such as API calls, see Application flow deployment-Call the service.