<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Databricks SQL Agent is failing in Generative AI</title>
    <link>https://community.databricks.com/t5/generative-ai/databricks-sql-agent-is-failing/m-p/88938#M532</link>
    <description>&lt;P&gt;Following up on&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/88823"&gt;@Walter_C&lt;/a&gt;&amp;nbsp;insights, I encountered the same issue and wanted to share the complete steps I took to fully resolve the issue:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1) Upgrade SQLAlchemy&lt;/STRONG&gt;: Running the following command before any other code resolved the &lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;sqlalchemy.types&lt;/SPAN&gt;&lt;/FONT&gt;&amp;nbsp;error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;%pip install --upgrade sqlalchemy&lt;/LI-CODE&gt;&lt;P&gt;&lt;STRONG&gt;2) Address LangChain Deprecation Warning&lt;/STRONG&gt;: I received a deprecation warning for the &lt;FONT color="#FF0000"&gt;OpenAI&lt;/FONT&gt; class in &lt;FONT color="#FF0000"&gt;LangChain&lt;/FONT&gt;:&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN class=""&gt;&lt;BR /&gt;"LangChainDeprecationWarning&lt;/SPAN&gt;: &lt;SPAN class=""&gt;The&lt;/SPAN&gt; &lt;SPAN class=""&gt;class&lt;/SPAN&gt; &lt;SPAN class=""&gt;`OpenAI`&lt;/SPAN&gt; was deprecated &lt;SPAN class=""&gt;in&lt;/SPAN&gt; &lt;SPAN class=""&gt;LangChain&lt;/SPAN&gt; &lt;SPAN class=""&gt;0.0&lt;/SPAN&gt;&lt;SPAN class=""&gt;.10&lt;/SPAN&gt; and will be removed &lt;SPAN class=""&gt;in&lt;/SPAN&gt; &lt;SPAN class=""&gt;0.3&lt;/SPAN&gt;&lt;SPAN class=""&gt;.0&lt;/SPAN&gt;. &lt;SPAN class=""&gt;An&lt;/SPAN&gt; updated version &lt;SPAN class=""&gt;of&lt;/SPAN&gt; the &lt;SPAN class=""&gt;class&lt;/SPAN&gt; &lt;SPAN class=""&gt;exists&lt;/SPAN&gt; &lt;SPAN class=""&gt;in&lt;/SPAN&gt; the langchain-openai package."&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;To resolve this:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;I replaced:&amp;nbsp;&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from langchain import OpenAI&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;with:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from langchain_openai import OpenAI&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;Before this definitely install the necessary packages again, this time including langchain-openai&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;%pip install --upgrade langchain databricks-sql-connector sqlalchemy langchain-openai&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;3) Update Method Call&lt;/STRONG&gt;: I switched from using &lt;FONT color="#FF0000"&gt;chain.run&lt;/FONT&gt; to &lt;FONT color="#FF0000"&gt;chain.invoke&lt;/FONT&gt; as the run method was deprecated:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;agent.invoke("What is the longest trip distance and how long did it take?")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I’ve uploaded the complete updated code to my GitHub. You can check it out here:&amp;nbsp;&lt;A href="https://github.com/amaan784/databricks-related/blob/main/Databricks%20Text%20to%20SQL%20using%20Langchain/sql-database-agent-langchain.ipynb" target="_blank" rel="noopener"&gt;Databricks Text to SQL using Langchain.ipynb&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After making these updates, everything worked smoothly. Hope this helps!&lt;/P&gt;</description>
    <pubDate>Sat, 07 Sep 2024 04:52:44 GMT</pubDate>
    <dc:creator>amaan784</dc:creator>
    <dc:date>2024-09-07T04:52:44Z</dc:date>
    <item>
      <title>Databricks SQL Agent is failing</title>
      <link>https://community.databricks.com/t5/generative-ai/databricks-sql-agent-is-failing/m-p/87171#M487</link>
      <description>&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Goal :&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;I want to build one Databricks SQL Agent using that any Databricks users can interact with a specified schema in Unity Catalog and generate insights on their data.&lt;/P&gt;&lt;P&gt;Followed the url as reference :&lt;A href="https://docs.databricks.com/en/large-language-models/langchain.html" target="_blank"&gt;https://docs.databricks.com/en/large-language-models/langchain.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;SampleCode:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;from langchain.agents import create_sql_agent&lt;BR /&gt;from langchain.agents.agent_toolkits import SQLDatabaseToolkit&lt;BR /&gt;from langchain.sql_database import SQLDatabase&lt;BR /&gt;from langchain import OpenAI&lt;/P&gt;&lt;P&gt;db = SQLDatabase.from_databricks(catalog="genai", schema="vector_db")&lt;BR /&gt;#llm = OpenAI(temperature=.7)&lt;BR /&gt;toolkit = SQLDatabaseToolkit(db=db, llm=llm_handler)&lt;BR /&gt;agent = create_sql_agent(llm=llm_handler, toolkit=toolkit, verbose=True)&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Error :&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;AttributeError: module 'sqlalchemy.types' has no attribute 'Uuid'&lt;BR /&gt;File &amp;lt;command-4275727126297453&amp;gt;, line 6&lt;BR /&gt;3 from langchain.sql_database import SQLDatabase&lt;BR /&gt;4 from langchain import OpenAI&lt;BR /&gt;----&amp;gt; 6 db = SQLDatabase.from_databricks(catalog="genai", schema="vector_db")&lt;BR /&gt;7 #llm = OpenAI(temperature=.7)&lt;BR /&gt;8 toolkit = SQLDatabaseToolkit(db=db, llm=llm_handler)&lt;BR /&gt;File /local_disk0/.ephemeral_nfs/envs/pythonEnv-21fa55bd-1c7c-42e6-8617-6775fdb15bae/lib/python3.11/site-packages/databricks/sqlalchemy/_types.py:35&lt;BR /&gt;13 """This method is supposed to accept a Python type and return a string representation of that type.&lt;BR /&gt;14 But due to some weirdness in the way SQLAlchemy's literal rendering works, we have to return&lt;BR /&gt;15 the value itself because, by the time it reaches our custom type code, it's already been converted&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Sep 2024 08:34:13 GMT</pubDate>
      <guid>https://community.databricks.com/t5/generative-ai/databricks-sql-agent-is-failing/m-p/87171#M487</guid>
      <dc:creator>SandipCoder</dc:creator>
      <dc:date>2024-09-02T08:34:13Z</dc:date>
    </item>
    <item>
      <title>Re: Databricks SQL Agent is failing</title>
      <link>https://community.databricks.com/t5/generative-ai/databricks-sql-agent-is-failing/m-p/87249#M490</link>
      <description>&lt;P class="_1t7bu9h1 paragraph"&gt;The error message you're seeing, &lt;CODE&gt;AttributeError: module 'sqlalchemy.types' has no attribute 'Uuid'&lt;/CODE&gt;, suggests that the SQLAlchemy library you're using doesn't have the 'Uuid' attribute.&lt;/P&gt;
&lt;P class="_1t7bu9h1 paragraph"&gt;This could be due to a few reasons:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;
&lt;P class="_1t7bu9h1 paragraph"&gt;&lt;STRONG&gt;Version Mismatch&lt;/STRONG&gt;: You might be using an older version of SQLAlchemy that doesn't support the 'Uuid' attribute. You can check your SQLAlchemy version by running &lt;CODE&gt;print(sqlalchemy.__version__)&lt;/CODE&gt;. If it's not the latest version, you might want to upgrade it using pip: &lt;CODE&gt;pip install --upgrade sqlalchemy&lt;/CODE&gt;.&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P class="_1t7bu9h1 paragraph"&gt;&lt;STRONG&gt;Incorrect Import&lt;/STRONG&gt;: Make sure you're importing the correct module. The 'Uuid' attribute is part of the &lt;CODE&gt;sqlalchemy.dialects.postgresql&lt;/CODE&gt; module, not the &lt;CODE&gt;sqlalchemy.types&lt;/CODE&gt; module. So, you should import it like this: &lt;CODE&gt;from sqlalchemy.dialects.postgresql import UUID&lt;/CODE&gt;.&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P class="_1t7bu9h1 paragraph"&gt;&lt;STRONG&gt;Dependency Issue&lt;/STRONG&gt;: There might be a dependency issue with the LangChain library. If the above solutions don't work, you might want to reach out to the LangChain support team for assistance.&lt;/P&gt;
&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Mon, 02 Sep 2024 16:00:22 GMT</pubDate>
      <guid>https://community.databricks.com/t5/generative-ai/databricks-sql-agent-is-failing/m-p/87249#M490</guid>
      <dc:creator>Walter_C</dc:creator>
      <dc:date>2024-09-02T16:00:22Z</dc:date>
    </item>
    <item>
      <title>Re: Databricks SQL Agent is failing</title>
      <link>https://community.databricks.com/t5/generative-ai/databricks-sql-agent-is-failing/m-p/88938#M532</link>
      <description>&lt;P&gt;Following up on&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/88823"&gt;@Walter_C&lt;/a&gt;&amp;nbsp;insights, I encountered the same issue and wanted to share the complete steps I took to fully resolve the issue:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1) Upgrade SQLAlchemy&lt;/STRONG&gt;: Running the following command before any other code resolved the &lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;sqlalchemy.types&lt;/SPAN&gt;&lt;/FONT&gt;&amp;nbsp;error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;%pip install --upgrade sqlalchemy&lt;/LI-CODE&gt;&lt;P&gt;&lt;STRONG&gt;2) Address LangChain Deprecation Warning&lt;/STRONG&gt;: I received a deprecation warning for the &lt;FONT color="#FF0000"&gt;OpenAI&lt;/FONT&gt; class in &lt;FONT color="#FF0000"&gt;LangChain&lt;/FONT&gt;:&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN class=""&gt;&lt;BR /&gt;"LangChainDeprecationWarning&lt;/SPAN&gt;: &lt;SPAN class=""&gt;The&lt;/SPAN&gt; &lt;SPAN class=""&gt;class&lt;/SPAN&gt; &lt;SPAN class=""&gt;`OpenAI`&lt;/SPAN&gt; was deprecated &lt;SPAN class=""&gt;in&lt;/SPAN&gt; &lt;SPAN class=""&gt;LangChain&lt;/SPAN&gt; &lt;SPAN class=""&gt;0.0&lt;/SPAN&gt;&lt;SPAN class=""&gt;.10&lt;/SPAN&gt; and will be removed &lt;SPAN class=""&gt;in&lt;/SPAN&gt; &lt;SPAN class=""&gt;0.3&lt;/SPAN&gt;&lt;SPAN class=""&gt;.0&lt;/SPAN&gt;. &lt;SPAN class=""&gt;An&lt;/SPAN&gt; updated version &lt;SPAN class=""&gt;of&lt;/SPAN&gt; the &lt;SPAN class=""&gt;class&lt;/SPAN&gt; &lt;SPAN class=""&gt;exists&lt;/SPAN&gt; &lt;SPAN class=""&gt;in&lt;/SPAN&gt; the langchain-openai package."&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;To resolve this:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;I replaced:&amp;nbsp;&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from langchain import OpenAI&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;with:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from langchain_openai import OpenAI&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;Before this definitely install the necessary packages again, this time including langchain-openai&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;%pip install --upgrade langchain databricks-sql-connector sqlalchemy langchain-openai&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;3) Update Method Call&lt;/STRONG&gt;: I switched from using &lt;FONT color="#FF0000"&gt;chain.run&lt;/FONT&gt; to &lt;FONT color="#FF0000"&gt;chain.invoke&lt;/FONT&gt; as the run method was deprecated:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;agent.invoke("What is the longest trip distance and how long did it take?")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I’ve uploaded the complete updated code to my GitHub. You can check it out here:&amp;nbsp;&lt;A href="https://github.com/amaan784/databricks-related/blob/main/Databricks%20Text%20to%20SQL%20using%20Langchain/sql-database-agent-langchain.ipynb" target="_blank" rel="noopener"&gt;Databricks Text to SQL using Langchain.ipynb&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After making these updates, everything worked smoothly. Hope this helps!&lt;/P&gt;</description>
      <pubDate>Sat, 07 Sep 2024 04:52:44 GMT</pubDate>
      <guid>https://community.databricks.com/t5/generative-ai/databricks-sql-agent-is-failing/m-p/88938#M532</guid>
      <dc:creator>amaan784</dc:creator>
      <dc:date>2024-09-07T04:52:44Z</dc:date>
    </item>
  </channel>
</rss>

