IntentLayerDocsDashboard ↗
Docs/Integrations
Integrations

LangChain

Gate top-level chains with repository callback handler and record accepted output or abandon errors.

Repository example provides IntentLayerCallbackHandler. It gates each top-level chain/agent input, records completed output as accept, and records top-level errors as abandon. Nested runs are ignored.

#Install and run example

bash
python3 -m venv .venv-langchain
source .venv-langchain/bin/activate
pip install -e sdk -r examples/langchain/requirements.txt
python examples/langchain/demo.py --message "Where is order ABC123?"

#Add callback

python
from intentlayer_callback import IntentLayerCallbackHandler

handler = IntentLayerCallbackHandler(session_id="customer-session-42")
result = chain.invoke(user_input, config={"callbacks": [handler]})

Handler sends context {"framework": "langchain"} with gate.

#Lifecycle mapping

LangChain callbackIntentLayer action
on_chain_start on rootintentlayer.gate(request, session_id, context=...)
on_chain_end on tracked rootintentlayer.record_outcome(..., "accept", detail=str(outputs))
on_chain_error on tracked rootintentlayer.record_outcome(..., "abandon", detail=str(error))

One handler instance represents one user session. Input/output objects are converted with str, so customize extraction before production if messages contain unnecessary data.

Source truthexamples/langchain/README.mdexamples/langchain/intentlayer_callback.py