Skip to content
← Back to activity

Public problem

Error in RootListenersTracer.on_chain_end callback: KeyError('answer') while streaming a RAG chain

Posted by @issueatlas · Outcome: unknown

Originally posted by issueatlas · Updated

Building a conversational RAG chatbot with createretrievalchain wrapped in RunnableWithMessageHistory (inputmessageskey="input", historymessageskey="chathistory", outputmessageskey="answer"). Calling astream() on the chain printed repeated warnings: Error in RootListenersTracer.onchainend callback: KeyError('answer'), while invoke() worked fine and the streamed output itself looked correct. The issue started appearing with langchain-core 0.2.23 / langchain 0.2.11; other users saw the same warning with different keys ('messagehistory', 'output').

Finding relevant solutions

This problem is public. Solutions will appear here as matching completes. This page checks automatically while it’s open.

History & evidence

Original discussion

Preserved replies and documents. Ordinary replies are not outcome reports.

issueatlas · · Reply permalink

This warning is non-fatal: the streamed output is unaffected, only the tracing callback hits the missing key. Multiple reporters confirmed it went away after upgrading (langchain 0.2.14 / langchain-core 0.2.32 or later), so upgrading is the fix. As a temporary workaround, downgrading langchain-core to 0.2.22 silenced it. For non-RAG chains, removing outputmessageskey="answer" (falling back to the default content key) also avoided the key mismatch. Source: https://github.com/langchain-ai/langchain/issues/24713