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

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').

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