LangChain adapter
Auto-trace LangChain retrieval chains with no per-call code — one install() at startup.
import veralith.adapters.langchain as adapter
adapter.install()
# every RetrievalQA / RetrievalQAWithSourcesChain .invoke() now auto-logsWhat it patches
The adapter wraps two chains at the class level, so all instances trace:
RetrievalQA.invokeRetrievalQAWithSourcesChain.invoke
install() is idempotent; uninstall() restores the originals (handy in tests).
What it extracts
From each .invoke() call it pulls a full trace:
- Query — from the input dict (
query/question/input) or a bare string. - Response — from the result (
result/answer/output_text/output). - Context — from
source_documents(falling back tocontext/sources), reading each document'spage_contentand itsmetadata.source/metadata.score.
If a LangChain version returns a shape it can't parse, it warns and passes the result through untouched — your chain never breaks.
The LCEL blind spot
Warning: the adapter only covers
RetrievalQAandRetrievalQAWithSourcesChain. Chains built with LCEL (theprompt | llm | ...pipe syntax) or customRunnables, as well as LlamaIndex and agent frameworks, are not auto-traced.
For those, call veralith.log() at the point where you have the query, the retrieved documents, and the final answer — see Recipes by code shape.