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
Hello! When using structured outputs within a node, I am getting back AIMessageChunks containing invalid_tool_calls with an error stating Malformed args. and error type being invalid_tool_call. Following the LangChain docs on .withStructuredOutput() from here and using that in LangGraph, results in AIMessageChunks containing for example:
The response/output of the chain run is complete and useful, but I noticed these invalid_tool_calls when using .streamEvents(). It does not seem to happen when using .stream(). When not using withStructuredOutput(), everything works as expected. Not sure if this is potentially related to #470.
Here's an example:
import{Annotation,START,StateGraph,END}from'@langchain/langgraph';import{BaseMessage,isAIMessageChunk}from'@langchain/core/messages';import{ChatOpenAI}from'@langchain/openai';import{z}from'zod';constGraphState=Annotation.Root({messages: Annotation<BaseMessage[]>({reducer: (x,y)=>x.concat(y),}),});constjoke=z.object({setup: z.string().describe('The setup of the joke'),punchline: z.string().describe('The punchline to the joke'),rating: z.number().optional().describe('How funny the joke is, from 1 to 10'),});constmodel=newChatOpenAI({model: 'gpt-4o-mini',temperature: 0,streaming: true,});constnodeFn=async(state: typeofGraphState.State)=>{constresponseMessages=awaitmodel.withStructuredOutput(joke).invoke(state.messages);return{messages: [responseMessages]};};constworkflow=newStateGraph(GraphState).addNode('node',nodeFn).addEdge(START,'node').addEdge('node',END);constapp=workflow.compile();conststream=app.streamEvents({messages: [{role: 'user',content: 'Tell me a joke about cats.'}]},{version: 'v2'},);forawait(const{ event, data }ofstream){if(event==='on_chat_model_stream'&&isAIMessageChunk(data.chunk)){console.log(data.chunk);}}
Hello! When using structured outputs within a node, I am getting back AIMessageChunks containing invalid_tool_calls with an error stating
Malformed args.
and error type beinginvalid_tool_call
. Following the LangChain docs on.withStructuredOutput()
from here and using that in LangGraph, results in AIMessageChunks containing for example:The response/output of the chain run is complete and useful, but I noticed these invalid_tool_calls when using
.streamEvents()
. It does not seem to happen when using.stream()
. When not usingwithStructuredOutput()
, everything works as expected. Not sure if this is potentially related to #470.Here's an example:
Using
@langchain/core ^0.3.18
,@langchain/langgraph ^0.2.20
, and@langchain/openai ^0.3.13
.LangSmith trace: https://smith.langchain.com/public/e2ee1092-6315-4bd4-a11d-9950d540a015/r
The text was updated successfully, but these errors were encountered: