Reputation: 1
I've been trying to troubleshoot this error by changing the agent prompt but can't seem to get it to work. For certain queries, the agent is invoking the correct query but is escaping the characters incorrectly which causes the query to fail during execution to the DB. I'm using the SQLDatabaseToolkit with a PostgreSQL connection and gemini-1.5-pro as the LLM. Here is the agent definition:
agent_executor = create_sql_agent(
prefix=prompt_template.format(top_k=top_k),
suffix=SQL_AGENT_SUFFIX,
llm=llm,
toolkit=toolkit,
top_k=top_k,
agent_type="tool-calling",
verbose=verbose,
max_iterations=max_iterations
)
And this is the model's step-by-step output:
Invoking: `sql_db_query_checker` with `{'query': 'SELECT * FROM product_sales WHERE "CustomerID" = \\\'SG-108901\\\''}`
SELECT * FROM product_sales WHERE "CustomerID" = 'SG-108901';
Invoking: `sql_db_query` with `{'query': 'SELECT * FROM product_sales WHERE \\"CustomerID\\" = \'SG-108901\' LIMIT 50'}`
Error: (psycopg2.errors.SyntaxError) syntax error at or near "\"
LINE 1: SELECT * FROM product_sales WHERE \"CustomerID\" = 'SG-10890...
^
[SQL: SELECT * FROM product_sales WHERE \"CustomerID\" = 'SG-108901' LIMIT 50]
(Background on this error at: https://sqlalche.me/e/20/f405)
Invoking: `sql_db_query` with `{'query': 'SELECT * FROM product_sales WHERE \\"CustomerID\\" = \'SG-108901\' LIMIT 50'}`
Error: (psycopg2.errors.SyntaxError) syntax error at or near "\"
LINE 1: SELECT * FROM product_sales WHERE \"CustomerID\" = 'SG-10890...
^
[SQL: SELECT * FROM product_sales WHERE \"CustomerID\" = 'SG-108901' LIMIT 50]
(Background on this error at: https://sqlalche.me/e/20/f405)
Invoking: `sql_db_query` with `{'query': 'SELECT * FROM product_sales WHERE \\"CustomerID\\" = \'SG-108901\' LIMIT 50'}`
Error: (psycopg2.errors.SyntaxError) syntax error at or near "\"
LINE 1: SELECT * FROM product_sales WHERE \"CustomerID\" = 'SG-10890...
^
[SQL: SELECT * FROM product_sales WHERE \"CustomerID\" = 'SG-108901' LIMIT 50]
(Background on this error at: https://sqlalche.me/e/20/f405)I am unable to fulfill this request due to repeated query failures. I have attempted to rewrite and execute the query multiple times, but continue to encounter errors. I need further assistance to resolve this issue.
> Finished chain.
Upvotes: 0
Views: 34