SQL command properly ended

(cx_Oracle.DatabaseError) ORA-00933: SQL command not properly ended
[SQL: SELECT state FROM add_master WHERE city = ‘Danvers’ FETCH FIRST 5 ROWS ONLY;]

Here, I am using default text-davinci-003 model, connected with my oracle database… while executing
response = SQLDatabaseChain.from_llm(llm=llm, db=db,verbose=True).run(conversation) this model… in response… getting this error…
Is there any way to remove semicolon in the intermediate step…
Thank you

A simple way to do so would be to always check whether the last element of the string is a semi-colon or not and if so, to remove it.

Other than that, you could add an instruction to the prompt to not add a semicolon at the end of the SQL command

1 Like

Going on from @udm17’s post, if you show an example (called a “shot”) Query string that does not contain a ; then the model will typically follow your lead.

2 Likes

is there any way to get an intermediate step, which generates sqlQuery from
response = SQLDatabaseChain.from_llm(llm=llm, db=db,verbose=True).run(conversation)… so that i can do transformation on that query and proceed the data fetching process

If you have a setup like this, it would be best to add a single sample to the prompt like @Foxalabs has suggested or you can add an instruction in the prompt to not end the SQL query with a ;.

I’m not sure if the chain will allow for an intermediate step

2 Likes

I haven’t worked with python or Oracle, but if you look at
SQLDatabaseChain.from_llm(llm=llm, db=db,verbose=True).run(conversation)
there are actually two function calls happening, first is to SQLDatabaseChain.from_llm(), and the value that is returned from that function, you then are calling .run() on it, while passing in I guess yoiur conversation context.

So if you break it up into multiple lines, you should be able to insert your own intermediate step.

  1. Capture the return value of from_llm() into a new variable.
  2. Run your custom logic on it (“does it end in a semi colon? if so, remove it” i think is what you are wanting?)
  3. call .run() on it, and set its return value into your “response” variable

Edit- by the way, it is awlays useful to dont crop out the line numebrs when you’re posting code

1 Like