Skip to content
NEWMarketplace and the trig8n Agent: sell what you build, and get plans and changes that are tested before you see them. See what is new

Library / AI Agents & Assistants

AI Agents & Assistants

Generate SQL Queries from MySQL Schema with OpenAI

When you run it, an OpenAI agent reads only the MySQL database schema to write SQL queries for your questions.

What it does

### LangChain AI Agent's system prompt is modified. It uses only the database schema to generate SQL queries. The agent creates these queries but does not execute them. Instead, it passes them to subsequent nodes. Example: "Can you show me the list of all German customers?" Queries are generated only when necessary; for some requests, a query may not be needed. This is because certain questions can be answered directly without SQL execution. Example: "Can you list me all tables?"

The steps

  1. OpenAI Chat Model
  2. Window Buffer Memory
  3. No Operation, do nothing
  4. List all tables in a database
  5. Extract database schema
  6. Add table name to output
  7. Convert data to binary
  8. Save file locally
  9. Extract data from file
  10. Chat Trigger
  11. AI Agent
  12. When clicking "Test workflow"
  13. Combine schema data and chat input
  14. Load the schema from the local file

26 steps in total.

Similar automations