Connect LLM to SQL database with LangChain SQLChain

How to Tutorial for using LangChain SQLChain

  1. Beginning the Process

First, ensure that PostgreSQL is installed on your machine and that you have an OpenAI account. If necessary, establish a new Python virtual environment before proceeding.

make sure to install requirements.txt from :

you will find the .json file on the repo as well

run :

if you wanna create some data on your postgres server

and then run :

if you do not have groq api just make one here:

initialise your server again

then create your ChatOpenAI object

import this libs

create a prompt

Run a query

you will get result like

>Entering new CustomSQLDatabaseSequentialChain chain...

Table names to use: ['employees', 'person']

Finished chain.

Query result: Question: Whom the person has a name starting with 'S'? SQLQuery:SELECT "name" FROM employees WHERE "name" LIKE 'S%';

run this as well if you wanna display the results :

by jojo @ig : suho0066

Last updated