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/anthropicEnvironment
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:
| Span | Captured from |
|---|---|
session contract-summarisation | VeriproofSession |
step summarise-contract | session.addStep() |
ChatPromptTemplate | LangChain — prompt formatting |
ChatAnthropic | LangChain — model invocation |
StringOutputParser | LangChain — 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
- Governance Session Builder — add EU AI Act metadata and decision records
- LangChain.js instrumentation reference — all captured span attributes
- TypeScript SDK Core reference — session and step builder API
Last updated on