SQLDatabaseChain: sqlite3.Warning: You can only execute one statement at a time.
Labels: name: area: agent, name: auto:bug, name: area: models

### System Info

langchain 0.0.246
Python 3.11.4
SQLAlchemy 1.4.39

### Who can help?

_No response_

### Information

- [ ] The official example notebooks/scripts
- [X] My own modified scripts

### Related Components

- [X] LLMs/Chat Models
- [ ] Embedding Models
- [X] Prompts / Prompt Templates / Prompt Selectors
- [ ] Output Parsers
- [ ] Document Loaders
- [ ] Vector Stores / Retrievers
- [ ] Memory
- [X] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

```
from langchain.chat_models import ChatOpenAI
from langchain.callbacks import get_openai_callback
from dotenv import load_dotenv, find_dotenv
from sqlalchemy import create_engine, MetaData, Table, Column, Integer, String, ForeignKey
from langchain.agents import initialize_agent
from langchain.sql_database import SQLDatabase
from langchain.chains import SQLDatabaseChain
from langchain.agents import Tool


def count_tokens(agent, query):
    with get_openai_callback() as cb:
        result = agent(query)
        print(f'Spent a total of {cb.total_tokens} tokens')

    return result

custom_dotenv_path = './openai.env'
_ = load_dotenv(custom_dotenv_path)
llm = ChatOpenAI(temperature=0, model_name="gpt-3.5-turbo")


engine = create_engine('sqlite:///college.db', echo=True)
meta = MetaData()

students = Table(
   'students', meta,
   Column('id', Integer, primary_key = True),
   Column('firstname', String),
   Column('lastname', String),
)

addresses = Table(
   'addresses', meta,
   Column('id', Integer, primary_key = True),
   Column('st_id', Integer, ForeignKey('students.id')),
   Column('zipcode', String),
   Column('email', String))

meta.create_all(engine)

conn = engine.connect()
conn.execute(students.insert(), [
    {'id': 1, 'firstname': 'John', 'lastname': 'Smith'},
    {'id': 2, 'firstname': 'Emily', 'lastname': 'Johnson'},
    {'id': 3, 'firstname': 'Michael', 'lastname': 'Rodriguez'},
    {'id': 4, 'firstname': 'Sarah', 'lastname': 'Kim'},
    {'id': 5, 'firstname': 'William', 'lastname': 'Brown'}
])
conn.execute(addresses.insert(), [
    {'st_id': 1, 'zipcode': '90210', 'email': 'john.smith@email.com'},
    {'st_id': 2, 'zipcode': '30301', 'email': 'emily.johnson@email.com'},
    {'st_id': 3, 'zipcode': '77001', 'email': 'michael.rodriguez@email.com'},
    {'st_id': 4, 'zipcode': '94101', 'email': 'sarah.kim@email.com'},
    {'st_id': 5, 'zipcode': '10001', 'email': 'william.brown@email.com'}
])


db = SQLDatabase(engine)

from langchain.prompts.prompt import PromptTemplate

_DEFAULT_TEMPLATE = """Given an input question, first create a syntactically correct {dialect} query to run, then look at the results of the query and return the answer.
Use the following format:

Question: "Question here"
SQLQuery: "SQL Query to run"
SQLResult: "Result of the SQLQuery"
Answer: "Final answer here"

Only use the following tables:

{table_info}

When a user requests to add a new record, adhere to the following steps:

Only have single quotes on any sql command sent to the engine. If you generate 'INSERT' statement for adding any record to the table. Please 'EXECUTE' one statement at a time.

Step 1.Student Table Entry:
Navigate to the 'students' table.
Input the desired first name and last name for the new record.

Step 2.Address Table Entry:
Once the student record is created, retrieve its 'id'.
Move to the 'addresses' table.
Using the retrieved 'id', prepare a new entry ensuring it consists of the 'student id', 'zipcode', and 'email' as initially provided.

Question: {input}"""
PROMPT = PromptTemplate(
    input_variables=["input", "table_info", "dialect"], template=_DEFAULT_TEMPLATE
)



db = SQLDatabase(engine)
sql_chain = SQLDatabaseChain.from_llm(llm=llm, db=db, verbose=True,
                            #use_query_checker=True,
                            prompt=PROMPT
)

tools =[
    Tool(
    name='student',
    func=sql_chain.run,
    description="Useful for when you need to answer questions about new student record"
    )
]

zero_shot_agent = initialize_agent(
    agent="zero-shot-react-description",
    tools=tools,
    llm=llm,
    verbose=True,
    max_iterations=5,
)

result = count_tokens(
    zero_shot_agent,
    "insert a new record with name Jane Everwood. Her email is 'everwood@gmail.com' and her zipcode is '99999'."
)
```

### Expected behavior

I asked ChatGPT to generate SQL for me to insert a new student record into the database. This database comprises two tables: students (cols: id, firstname, lastname) and addresses (cols: id, st_id, zipcode, email). When I input "insert a new record with the name Jane Everwood. Her email is 'everwood@gmail.com' and her zipcode is '99999'", the system should add one record to the students table and one corresponding record to the addresses table. Instead, I received a "sqlite3.Warning: You can only execute one statement at a time" message. 

The generated SQL scripts from SQLDatabaseChain appear correct. Could the issue be related to calling "cursor.execute(statement, parameters)" to execute multiple statements? Thanks!

Here is the full message that I got:
```
> Entering new AgentExecutor chain...
I need to insert a new student record with the given information.
Action: student
Action Input: insert new record with name Jane Everwood, email 'everwood@gmail.com', and zipcode '99999'

> Entering new SQLDatabaseChain chain...
insert new record with name Jane Everwood, email 'everwood@gmail.com', and zipcode '99999'
SQLQuery:2023-08-22 15:44:43,547 INFO sqlalchemy.engine.Engine SELECT students.id, students.firstname, students.lastname 
FROM students
 LIMIT ? OFFSET ?
2023-08-22 15:44:43,548 INFO sqlalchemy.engine.Engine [generated in 0.00041s] (3, 0)
2023-08-22 15:44:43,551 INFO sqlalchemy.engine.Engine SELECT addresses.id, addresses.st_id, addresses.zipcode, addresses.email 
FROM addresses
 LIMIT ? OFFSET ?
2023-08-22 15:44:43,551 INFO sqlalchemy.engine.Engine [generated in 0.00025s] (3, 0)
INSERT INTO students (firstname, lastname) VALUES ('Jane', 'Everwood');
INSERT INTO addresses (st_id, zipcode, email) VALUES ((SELECT id FROM students WHERE firstname = 'Jane' AND lastname = 'Everwood'), '99999', 'everwood@gmail.com');2023-08-22 15:44:45,160 INFO sqlalchemy.engine.Engine BEGIN (implicit)
2023-08-22 15:44:45,162 INFO sqlalchemy.engine.Engine INSERT INTO students (firstname, lastname) VALUES ('Jane', 'Everwood');
INSERT INTO addresses (st_id, zipcode, email) VALUES ((SELECT id FROM students WHERE firstname = 'Jane' AND lastname = 'Everwood'), '99999', 'everwood@gmail.com');
2023-08-22 15:44:45,162 INFO sqlalchemy.engine.Engine [generated in 0.00026s] ()
2023-08-22 15:44:45,162 INFO sqlalchemy.engine.Engine ROLLBACK
Traceback (most recent call last):
  File "C:\_PyCharmProject\openai\bug_report.py", line 117, in <module>
    result = count_tokens(
  File "C:\_PyCharmProject\openai\bug_report.py", line 13, in count_tokens
    result = agent(query)
  File "C:\Users\xl\AppData\Roaming\Python\Python39\site-packages\langchain\chains\base.py", line 258, in __call__
    raise e
  File "C:\Users\xl\AppData\Roaming\Python\Python39\site-packages\langchain\chains\base.py", line 252, in __call__
    self._call(inputs, run_manager=run_manager)
  File "C:\Users\xl\AppData\Roaming\Python\Python39\site-packages\langchain\agents\agent.py", line 1029, in _call
    next_step_output = self._take_next_step(
  File "C:\Users\xl\AppData\Roaming\Python\Python39\site-packages\langchain\agents\agent.py", line 890, in _take_next_step
    observation = tool.run(
  File "C:\Users\xl\AppData\Roaming\Python\Python39\site-packages\langchain\tools\base.py", line 320, in run
    raise e
  File "C:\Users\xl\AppData\Roaming\Python\Python39\site-packages\langchain\tools\base.py", line 292, in run
    self._run(*tool_args, run_manager=run_manager, **tool_kwargs)
  File "C:\Users\xl\AppData\Roaming\Python\Python39\site-packages\langchain\tools\base.py", line 444, in _run
    self.func(
  File "C:\Users\xl\AppData\Roaming\Python\Python39\site-packages\langchain\chains\base.py", line 451, in run
    return self(args[0], callbacks=callbacks, tags=tags, metadata=metadata)[
  File "C:\Users\xl\AppData\Roaming\Python\Python39\site-packages\langchain\chains\base.py", line 258, in __call__
    raise e
  File "C:\Users\xl\AppData\Roaming\Python\Python39\site-packages\langchain\chains\base.py", line 252, in __call__
    self._call(inputs, run_manager=run_manager)
  File "C:\Users\xl\AppData\Roaming\Python\Python39\site-packages\langchain\chains\sql_database\base.py", line 186, in _call
    raise exc
  File "C:\Users\xl\AppData\Roaming\Python\Python39\site-packages\langchain\chains\sql_database\base.py", line 131, in _call
    result = self.database.run(sql_cmd)
  File "C:\Users\xl\AppData\Roaming\Python\Python39\site-packages\langchain\utilities\sql_database.py", line 390, in run
    cursor = connection.execute(text(command))
  File "C:\ProgramData\Anaconda3\lib\site-packages\sqlalchemy\engine\base.py", line 1306, in execute
    return meth(self, multiparams, params, _EMPTY_EXECUTION_OPTS)
  File "C:\ProgramData\Anaconda3\lib\site-packages\sqlalchemy\sql\elements.py", line 332, in _execute_on_connection
    return connection._execute_clauseelement(
  File "C:\ProgramData\Anaconda3\lib\site-packages\sqlalchemy\engine\base.py", line 1498, in _execute_clauseelement
    ret = self._execute_context(
  File "C:\ProgramData\Anaconda3\lib\site-packages\sqlalchemy\engine\base.py", line 1862, in _execute_context
    self._handle_dbapi_exception(
  File "C:\ProgramData\Anaconda3\lib\site-packages\sqlalchemy\engine\base.py", line 2047, in _handle_dbapi_exception
    util.raise_(exc_info[1], with_traceback=exc_info[2])
  File "C:\ProgramData\Anaconda3\lib\site-packages\sqlalchemy\util\compat.py", line 208, in raise_
    raise exception
  File "C:\ProgramData\Anaconda3\lib\site-packages\sqlalchemy\engine\base.py", line 1819, in _execute_context
    self.dialect.do_execute(
  File "C:\ProgramData\Anaconda3\lib\site-packages\sqlalchemy\engine\default.py", line 732, in do_execute
    cursor.execute(statement, parameters)
sqlite3.Warning: You can only execute one statement at a time.

Process finished with exit code 1

```