Skip to Content

LangChain.js

Automatically capture spans for every LangChain.js chain, prompt template, tool call, and retrieval step using the VeriProof LangChain.js instrumentation adapter.

TypeScriptLangChain.jsNode.js ≥ 18

Prerequisites

npm install @veriproof/sdk-core @veriproof/sdk-instrumentation-langchainjs @langchain/core @langchain/anthropic

Environment

VERIPROOF_API_KEY=vp_live_... VERIPROOF_APPLICATION_ID=my-langchain-app ANTHROPIC_API_KEY=sk-ant-...

Complete example

import { configureVeriproof, VeriproofSdkOptions, VeriproofSession, SessionIntent, RiskLevel, StepOutcome, StepType } from '@veriproof/sdk-core'; import { VeriproofLangChainJSInstrumentation } from '@veriproof/sdk-instrumentation-langchainjs'; import { ChatAnthropic } from '@langchain/anthropic'; import { ChatPromptTemplate } from '@langchain/core/prompts'; import { StringOutputParser } from '@langchain/core/output_parsers'; // 1. Configure VeriProof with the LangChain instrumentation adapter const { provider } = configureVeriproof( VeriproofSdkOptions.createDevelopment({ apiKey: process.env.VERIPROOF_API_KEY!, applicationId: process.env.VERIPROOF_APPLICATION_ID!, }), { serviceName: process.env.VERIPROOF_APPLICATION_ID!, setGlobal: true, instrumentations: [new VeriproofLangChainJSInstrumentation()], }, ); process.on('SIGTERM', async () => { await provider.shutdown(); }); // 2. Build a governance session const session = new VeriproofSession({ applicationId: process.env.VERIPROOF_APPLICATION_ID!, sessionName: 'contract-summarisation', intent: SessionIntent.ANALYSIS, }); await session.addStep({ stepName: 'summarise-contract', stepType: StepType.ANALYSIS, input: { documentId: 'contract:C-2026-0042', pageCount: 18 }, }); // 3. Build and invoke a LangChain chain — all spans captured automatically const model = new ChatAnthropic({ model: 'claude-3-5-haiku-20241022', maxTokens: 512 }); const prompt = ChatPromptTemplate.fromMessages([ ['system', 'You are a legal analyst. Summarise the key obligations of each party.'], ['human', '{contract_text}'], ]); const chain = prompt.pipe(model).pipe(new StringOutputParser()); const summary = await chain.invoke({ contract_text: '...contract text here...', }); // 4. Record outcome and complete await session.setDecision({ decisionSummary: summary, riskLevel: RiskLevel.LOW, outcome: StepOutcome.COMPLETED, }); const result = await session.complete(); console.log('Session ID:', result.sessionId);

What you’ll see in VeriProof

The LangChain.js instrumentation creates child spans for each step in the chain:

SpanCaptured from
session contract-summarisationVeriproofSession
step summarise-contractsession.addStep()
ChatPromptTemplateLangChain — prompt formatting
ChatAnthropicLangChain — model invocation
StringOutputParserLangChain — output parsing

All LangChain spans are automatically linked as children of the VeriProof session span, so the full chain execution is visible as a single trace in the dashboard.


Next steps

Last updated on