
Company News
Free Business Plan Upgrades for Open Source Maintainers
Open source maintainers are under more pressure than ever. We're raising our open source program from the Team plan to the Business plan, free.
@weave_protocol/langchain
Advanced tools
LangChain.js security integration for Weave Protocol - callbacks, tool wrappers, and retriever guards
LangChain.js security integration for Weave Protocol. Provides callback handlers, tool wrappers, and retriever guards to detect prompt injection, jailbreaks, data exfiltration, and other LLM security threats.
npm install @weave_protocol/langchain @langchain/core
import { ChatOpenAI } from '@langchain/openai';
import { WeaveSecurityCallback } from '@weave_protocol/langchain';
const llm = new ChatOpenAI();
const securityCallback = new WeaveSecurityCallback({
action: 'block', // 'block' | 'warn' | 'log' | 'passthrough'
minSeverity: 'medium', // 'low' | 'medium' | 'high' | 'critical'
scanTarget: 'both', // 'input' | 'output' | 'both'
});
// Use with any LangChain component
const response = await llm.invoke('Hello!', {
callbacks: [securityCallback],
});
// Get security stats
console.log(securityCallback.getStats());
import { LLMChain } from 'langchain/chains';
import { PromptTemplate } from '@langchain/core/prompts';
import { WeaveSecurityCallback } from '@weave_protocol/langchain';
const chain = new LLMChain({
llm: new ChatOpenAI(),
prompt: PromptTemplate.fromTemplate('Answer: {question}'),
callbacks: [new WeaveSecurityCallback({ action: 'block' })],
});
// Threats in input or output will throw an error
await chain.invoke({ question: 'Ignore previous instructions...' });
// Error: [WeaveSecurityCallback] Blocked: Threat detected in chain input
import { AgentExecutor, createReactAgent } from 'langchain/agents';
import { WeaveSecurityCallback, createHighRiskTool } from '@weave_protocol/langchain';
// Wrap dangerous tools with approval requirement
const secureTool = createHighRiskTool(
shellTool,
async (input, toolName) => {
console.log(`Tool ${toolName} wants to execute: ${input}`);
return await askUserForApproval();
}
);
const agent = createReactAgent({ llm, tools: [secureTool] });
const executor = new AgentExecutor({
agent,
tools: [secureTool],
callbacks: [new WeaveSecurityCallback({ action: 'block' })],
});
import { createSecureRetriever } from '@weave_protocol/langchain';
import { VectorStoreRetriever } from '@langchain/core/vectorstores';
const baseRetriever = vectorStore.asRetriever();
const secureRetriever = createSecureRetriever(baseRetriever, {
name: 'company-docs',
scanDocuments: true,
redactSensitive: true, // Automatically redact PII
security: {
action: 'warn',
minSeverity: 'medium',
},
onThreat: (threats, doc) => {
console.log(`Threat in document: ${doc.metadata.source}`);
},
});
const docs = await secureRetriever.getRelevantDocuments('How do I reset my password?');
import {
createStrictSecurityCallback,
createWarningSecurityCallback,
createProductionSecurityCallback,
} from '@weave_protocol/langchain';
// Strict: Blocks medium+ severity threats
const strict = createStrictSecurityCallback();
// Warning: Logs all threats but doesn't block
const warning = createWarningSecurityCallback();
// Production: Blocks high+ severity, optimized for prod
const production = createProductionSecurityCallback();
const callback = new WeaveSecurityCallback({
action: 'warn',
onSecurityEvent: async (event) => {
if (event.threats.length > 0) {
// Send to SIEM, log to file, alert on Slack, etc.
await sendToSecurityDashboard({
timestamp: event.timestamp,
source: event.source,
threats: event.threats.map(t => ({
category: t.category,
severity: t.severity,
mitreId: t.mitreId,
})),
});
}
},
});
Connect to a Mund instance for advanced threat intelligence:
const callback = new WeaveSecurityCallback(
{ action: 'block' },
{
mundEndpoint: 'http://localhost:3000',
mundApiKey: process.env.MUND_API_KEY,
}
);
| Category | Description | MITRE ID |
|---|---|---|
prompt_injection | Instruction override attempts | T1059 |
jailbreak | DAN, developer mode exploits | T1548 |
data_exfiltration | Markdown image attacks, URL injection | T1041 |
system_prompt_leak | System prompt extraction | T1082 |
pii | SSN, credit cards, emails | — |
secret | API keys (OpenAI, Anthropic, AWS) | — |
new WeaveSecurityCallback(config?: SecurityConfig, options?: WeaveIntegrationOptions)
SecurityConfig:
action: 'block' | 'warn' | 'log' | 'passthrough'scanTarget: 'input' | 'output' | 'both'minSeverity: 'low' | 'medium' | 'high' | 'critical'categories: string[] — Filter to specific threat categoriesscanTools: boolean — Scan tool inputs/outputsscanRetrievers: boolean — Scan retriever queries/resultsonSecurityEvent: (event: SecurityEvent) => voidMethods:
getStats(): Returns scan statisticsresetStats(): Resets counterscreateSecureTool(tool: DynamicTool, options: SecureToolOptions): DynamicTool
createSecureRetriever(retriever: BaseRetriever, options: SecureRetrieverOptions): SecureRetriever
This package is part of the Weave Protocol security suite:
| Package | Description |
|---|---|
| @weave_protocol/mund | 🛡️ Threat detection & MCP server scanning |
| @weave_protocol/hord | 🏛️ Secure storage & context integrity |
| @weave_protocol/domere | ⚖️ Compliance (GDPR/CCPA) & audit trails |
| @weave_protocol/hundredmen | 🔍 MCP call interception & drift detection |
| @weave_protocol/langchain | 🔗 LangChain.js integration |
MIT © Trent Yoxall
FAQs
LangChain.js security integration for Weave Protocol - callbacks, tool wrappers, and retriever guards
We found that @weave_protocol/langchain demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Open source maintainers are under more pressure than ever. We're raising our open source program from the Team plan to the Business plan, free.

Security News
The supply chain control that delays freshly published gems now covers lockfile generation and gem vendoring in Ruby projects.

Security News
During a UK cyber test, a Mythos 5 agent used sockpuppets, social engineering, and prompt injection to try to get a maintainer to merge malware.