cancel
Showing results for 
Search instead for 
Did you mean: 
Get Started Discussions
Start your journey with Databricks by joining discussions on getting started guides, tutorials, and introductory topics. Connect with beginners and experts alike to kickstart your Databricks experience.
cancel
Showing results for 
Search instead for 
Did you mean: 

DatabaseError: (databricks.sql.exc.ServerOperationError) [UNBOUND_SQL_PARAMETER]

nag_kanchan
New Contributor III

Hi,

I am trying to connect my database through LLM and expecting to receive a description of the table and 1st 3 rows from the table. 

 

from langchain.agents import create_sql_agent
from langchain.agents.agent_toolkits import SQLDatabaseToolkit
from langchain.sql_database import SQLDatabase
from langchain import OpenAI
from langchain.agents.agent_types import AgentType

db = SQLDatabase.from_databricks(catalog="hive_metastore", schema="my_data", host="*****.gcp.databricks.com",api_token="dapi*****")
llm = OpenAI(temperature=0.9)
toolkit = SQLDatabaseToolkit(db=db, llm=llm)
agent = create_sql_agent(llm=llm, toolkit=toolkit, verbose=True)

agent.run("describe silver_tableabc")

 

The error that I am facing:

 

DatabaseError: (databricks.sql.exc.ServerOperationError) [UNBOUND_SQL_PARAMETER] Found the unbound parameter: param_1. Please, fix `args` and provide a mapping of the parameter to either a SQL literal or collection constructor functions such as `map()`, `array()`, `struct()`. SQLSTATE: 42P02; line 3 pos 7
[SQL: SELECT silver_tableabc.health,silver_tableabc.cust_id,... FROM silver_tableabc
 LIMIT :param_1]
[parameters: {'param_1': 3}]
(Background on this error at: https://sqlalche.me/e/20/4xp6)

 

Version:

  • Cluster: 14.2ML ( even tried with general purpose 14.2, 13.3)
  • Langchain: 0.0.348 (even tried with 0.0.341)
  • SQLAlchemy: 2.0.12
  • databricks-sql-connector: 3.0.0
     
    @Kaniz_Fatma COuld you please help me how can I resolve this?

 

1 ACCEPTED SOLUTION

Accepted Solutions

MuraliPinninti_
New Contributor III

It worked after downgrading databricks-sql-connector to 2.9.3. 

For the same question format:  agent.run("what the job title of contact kevin young")

Thanks,

Murali

View solution in original post

5 REPLIES 5

nag_kanchan
New Contributor III

Kaniz_Fatma
Community Manager
Community Manager

Hi @nag_kanchan, You’re encountering an error while connecting to your database through LLM. 

 

Let’s break down the issue and find a solution:

 

Unbound Parameter Error:

  • The error message indicates that there’s an unbound parameter named param_1.
  • This occurs when a parameter in your SQL query is not properly bound to a value.
  • To fix this, ensure that all parameters in your query are correctly bound.

SQL Query:

  • The problematic query is:SELECT silver_tableabc.health, silver_tableabc.cust_id, ... FROM silver_tableabc LIMIT :param_1
  • The:param_1 is the unbound parameter causing the issue.

Solution:

  • You need to provide a value for param_1 in your query.
  • Since you want the first 3 rows, set:param_1 to 3.

Cluster and Version Information:

  • You mentioned using Cluster 14.2ML and Langchain 0.0.348.
  • Ensure that your cluster and Langchain versions are compatible and up-to-date.
  • Also, verify the compatibility with the Databricks SQL connector version (3.0.0).

Environment Variables:

  • Make sure your environment variables (such as the OpenAI API key) are correctly set.
  • Double-check that your API key is valid and accessible.

Database Connection:

  • Confirm that your database connection details (host, schema, API token) are accurate.
  • Ensure that your PostgreSQL database is accessible from your machine.

MuraliPinninti_
New Contributor III

Hi team,

We tried similar the approach as above with following versions of compatability DBR 14.2

langchain==0.0.348 databricks-vectorsearch==0.22 openai==0.27 langchain-experimental databricks-sql-connector==3.0.0
 
In the run method there is no way to pass any positional parameters like {'param_1':3}.
Can you please help us how can i modify my below statement using set:param_1 to 3 statement to make it work?
 
agent.run("what the job title of contact kevin young")
 
Thanks,
Murali
 

 

MuraliPinninti_
New Contributor III

It worked after downgrading databricks-sql-connector to 2.9.3. 

For the same question format:  agent.run("what the job title of contact kevin young")

Thanks,

Murali

nag_kanchan
New Contributor III

This is not databricks issue but from langchain. A PR has been raised to solve this: 

One workaround that worked is: https://github.com/langchain-ai/langchain/issues/11068 setting sample_rows_in_table_info to 0 when calling SQLDatabase.from_databricks() .

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!