You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

LangChain中SQLDatabase.from_uri多Schema配置失败,求技术解决方案

在LangChain中配置多数据库Schema失败求助

尝试通过LangChain的SQLDatabase.from_uri方法配置多个数据库Schema,但所有尝试均未成功,具体操作如下:

方法1:直接指定多个Schema

尝试在schema参数中传入多个Schema的逗号分隔值:

db= SQLDatabase.from_uri(
    odbc_str, #db connection string
    schema="schema1,schema2",
    #include_tables=['schema1.tableA', 'schema2.tableB', 'schema2.tableC'],
    view_support=True
)
sql_toolkit = SQLDatabaseToolkit(db=db, llm=llm)
sql_toolkit.get_tools()

方法2:创建多个SQLDatabase实例传入Toolkit

分别创建对应不同Schema的SQLDatabase实例,再将列表传入SQLDatabaseToolkit:

db1= SQLDatabase.from_uri(
    odbc_str, #db connection string
    schema="schema1",
    #include_tables=['tableA'],
    view_support=True
)
db2= SQLDatabase.from_uri(
    odbc_str, #db connection string
    schema="schema2",
    #include_tables=['tableB','tableC'],
    view_support=True
)
sql_toolkit = SQLDatabaseToolkit(db=[db1, db2], llm=llm)
sql_toolkit.get_tools()

sqldb_agent = create_sql_agent(
    llm=llm,
    toolkit=sql_toolkit,
    agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
    verbose=True,
    handle_parsing_errors=True,
    view_support=True

)

额外尝试:仅连接数据库期望自动识别所有Schema

尝试不指定Schema,直接通过SQLDatabase.from_uri连接数据库,期望SQL Agent能识别所有Schema,但SQL Toolkit未正常工作,Agent执行sql_db_list_tables时返回空结果:

> Entering new AgentExecutor chain...
Action: sql_db_list_tables
Action Input: ""
Observation: 
Thought:I have obtained a list of tables in the database. Now I can query the schema of the relevant tables.

恳请各位提供解决方案!

内容的提问来源于stack exchange,提问作者Nikk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 18:18:10