You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I searched the LangChain documentation with the integrated search.
I used the GitHub search to find a similar question and didn't find it.
I am sure that this is a bug in LangChain rather than my code.
The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
Example Code
from langchain_openai import ChatOpenAI
from pydantic import BaseModel, Field
from langchain.tools import StructuredTool
class ResponseModel(BaseModel):
a_value:str = Field(description="This doesn't matter much")
def a_func(val: int):
return True
a_tool = StructuredTool.from_function(
func=a_func,
name="A func",
description="A function you will need",
)
llm = ChatOpenAI(model="gpt-4o-mini",temperature=0)
structured_llm = llm.with_structured_output(ResponseModel)
llm_with_tools = structured_llm.bind_tools([a_tool]) <----- not available
Error Message and Stack Trace (if applicable)
'RunnableSequence' object has no attribute 'bind_tools'
Description
I am attempting to retrieved structured output in a json format (to pass via an api to a frontend), and I also require calling out to tools. I cannot figure out how to combine the two, or there is an issue with code to do so.
System Info
System Information
OS: Darwin
OS Version: Darwin Kernel Version 24.1.0: Thu Oct 10 21:02:27 PDT 2024; root:xnu-11215.41.3~2/RELEASE_X86_64
Python Version: 3.13.1 (main, Dec 3 2024, 17:59:52) [Clang 16.0.0 (clang-1600.0.26.4)]
@p3nnst8r I don't know what you are trying to achieve, but essentially, with_structured_output returns a RunnableSequence that consists of the following two Runnables: RunnableBinding (where ChatOpenAI is binding, and the given schema is passed as an additional parameter to tools) -> OutputParser.
So, calling bind_tools again on the RunnableSequence is causing this error.
This is not recommended, but if you want to use additional tools in the same RunnableSequence, you can do the following:
However, I still don't understand why you want to use additional tools when with_structured_output is only used to make the LLM parse the result into a specific format. It is recommended that you initiate a different instance of the LLM with the desired tools.
Checked other resources
Example Code
Error Message and Stack Trace (if applicable)
'RunnableSequence' object has no attribute 'bind_tools'
Description
I am attempting to retrieved structured output in a json format (to pass via an api to a frontend), and I also require calling out to tools. I cannot figure out how to combine the two, or there is an issue with code to do so.
System Info
System Information
Package Information
Optional packages not installed
Other Dependencies
The text was updated successfully, but these errors were encountered: