Best Way to Connect Dify or Flowise to a SQL Database
One HTTP tool answers up to five questions. Dify and Flowise do not get a database login. Writes wait for Guard.
Claix · November 2026. Related guides: Make and Zapier, typed JSON answers, and call an agent. Product: Claix Retrieve and Claix Guard.
Dify and Flowise are great for building AI agents. When you connect them to a SQL database, the question changes. It is no longer only “How do I connect this app to that app?” It becomes “How do I let an AI agent use live business data without giving it unrestricted access to my database?”
This guide explains the best way to connect Dify or Flowise to a SQL database, how to use one tool instead of one per query, and how to control writes with Claix.
Why Dify and Flowise need a database layer
Dify and Flowise connect prompts, tools and workflows. An agent can receive an instruction, decide what it needs, call a tool and act on the result. A generic database connection gives that agent a database. It does not define which tables it should read, which columns it can retrieve, which records belong to a particular user, or which writes are allowed. You need a control layer between the agent and the database.
The two halves of the problem
| Problem | What it controls | What Claix provides |
|---|---|---|
| What can the agent read? | Tables, columns, rules and answer format | Claix Retrieve |
| What can the agent change? | Inserts, updates and deletes | Claix Guard |
Claix Retrieve controls what your agents can read. Claix Guard controls what they can change.
What Claix Retrieve does
Claix Retrieve connects to a relational database and lets each agent retrieve only the tables and columns you allow, within the rules and limits you define. It does not copy your data into a vector store. Agents query the database where the data lives. A smaller retrieval surface means less exposure.
Routes define what an agent can read
A route specifies which tables an agent can access, which columns it can retrieve, and a guide with your rules and vocabulary. You create a route once and attach it to as many agents as you need. A support agent may see orders and customers. An operations agent may see inventory and shifts. An internal analytics agent can have a wider route. The route is the boundary.
Agents define who can access what
An agent is the identity that uses one or more routes. Each agent has its own endpoint, business prompt, attached routes and response mode. You set that mode in the dashboard. It is not a field in the request. A support bot and an internal assistant can share the same database while seeing different data. In Dify and Flowise, point each agent at the Claix agent that matches its job.
One tool instead of one per query
A common mistake is a separate tool for stock, order status, customer details, inventory and reservations. Each tool has to be defined, maintained and tested. Claix Retrieve is one HTTP tool. Send POST https://claix.dev/retrieve/{agent_name} with header x-api-key. Each question can include a format. One call accepts up to five questions.
{
"questions": [
{ "question": "How many orders are confirmed?", "format": "int" },
{ "question": "What is the name of the customer with the most orders?", "format": "string" }
]
}The response fields are user_ask, ia_response and log_id. ia_response follows the question order. Use log_id in Traces. Docs: call an agent.
How to call Claix Retrieve from Dify
- Add an HTTP Request node.
- Set the method to POST.
- Set the URL to https://claix.dev/retrieve/{agent_name}.
- Send the API key in the x-api-key header.
- Send the JSON body with the questions.
How to call Claix Retrieve from Flowise
Use the same HTTP Request node: POST, the same URL, the same x-api-key header and the same JSON body.
What you get back
| Mode | What you get |
|---|---|
| Raw | JSON rows returned by the database, as { rows, truncated } |
| Reasoned | A single typed value per question |
In reasoned mode the value matches the format you requested: a boolean, a number, a list or a JSON object. The workflow can branch on that value instead of parsing a sentence. If the tables on the route do not contain the answer, the field comes back empty instead of a guess.
Why this is better than direct database access
Direct access leaves you to control tables, columns, tenant rows, result size, writes and failures yourself. Retrieve validates queries before they run and traces every request. It does not replace a dedicated read-only database role. Connect it with one.
How to control writes
Guard checks a proposed INSERT, UPDATE or DELETE against rules you approved. Allowed means your node can execute the statement. Denied means it should not, and the agent receives the reason. Needs approval means the write waits for a person. Claix does not execute the statement. Your workflow does, with its own credentials. A denial is still HTTP 200. Read allowed.
In Dify or Flowise, add an HTTP Request node that calls POST /check-sql before the node that writes. sql is required. params follows placeholder order. connection_id is required only when the account has more than one active connection. Docs: check SQL.
What Guard can enforce
| Control | What it prevents |
|---|---|
| Operation type | Unwanted inserts, updates or deletes |
| Target table | Changes to tables outside the agent’s scope |
| Target columns | Changes to sensitive or protected fields |
| Record selection | Updates or deletes that affect too many records |
| Value limits | Discounts, quantities, amounts or statuses outside allowed ranges |
| State transitions | Invalid changes from one status to another |
| Rate limits | Too many changes in a short period |
| Human review | High-risk actions that require approval |
| Audit trail | Missing evidence of what was proposed and decided |
- Agents can create and update orders, but never delete them.
- Agents can update an order status, but never its price.
- Discounts cannot exceed 20 percent.
- Refunds above a threshold require human review.
- An update or delete must target a specific record.
- Certain status transitions are not allowed.
- The number of refunds per hour is limited.
How to get started
Claix supports any SQL database, including Postgres, MySQL and MariaDB, plus Postgres-compatible setups such as Supabase. Connect with a read-only role. Define routes and agents, then call one endpoint. Guard, for writes, supports PostgreSQL, MySQL and MariaDB. Keep write credentials in the node that runs the statement, not in the agent.
Conclusion
Dify and Flowise are a good place to build an agent. The database connection still needs a boundary. One Retrieve tool answers from the tables and columns you allow. Guard checks a proposed write before your workflow runs it. Traces show what was asked and what came back. Do not give the agent unrestricted database access.
You might also like…
Guides · Automation
Best Way to Connect a Make or Zapier AI Agent to Your Database
Guides · Retrieval
Best Way to Get Structured JSON From a Database With an AI Agent
Guides · Retrieval
Text-to-SQL vs Predefined Queries: Which Should Your AI Agent Use?
Guides · Supabase
How to Give an AI Agent Safe Access to Your Supabase Database with Claix