🚨 Active Supply Chain Attack:node-ipc Package Compromised.Learn More
Socket
Book a DemoSign in
Socket

@aegis-sdk/langchain

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aegis-sdk/langchain

LangChain.js adapter for Aegis prompt injection defense

latest
Source
npmnpm
Version
0.5.0
Version published
Weekly downloads
9
-30.77%
Maintainers
1
Weekly downloads
 
Created
Source

@aegis-sdk/langchain

LangChain.js callback handler and chain guard for prompt injection defense.

Part of the Aegis.js prompt injection defense toolkit.

Installation

npm install @aegis-sdk/langchain @aegis-sdk/core

Quick Start

import { ChatOpenAI } from '@langchain/openai';
import { Aegis } from '@aegis-sdk/core';
import { createAegisCallback } from '@aegis-sdk/langchain';

const aegis = new Aegis({ policy: 'strict' });

const model = new ChatOpenAI({
  callbacks: [createAegisCallback(aegis)],
});

const result = await model.invoke('Hello!');

API

createAegisCallback(optionsOrAegis?)

Creates a LangChain-compatible callback handler that intercepts LLM and tool lifecycle events:

  • handleLLMStart -- Scans input prompts for injection patterns
  • handleLLMEnd -- Quarantines LLM output for safe downstream consumption
  • handleToolStart -- Validates tool calls against the Aegis policy
  • handleToolEnd -- Quarantines tool output

Accepts an Aegis instance, AegisConfig, or AegisCallbackOptions:

OptionTypeDefaultDescription
aegisAegisConfig | Aegis{}Aegis configuration or pre-constructed instance
scanInputbooleantrueScan LLM input prompts
scanOutputbooleantrueScan LLM output for violations
validateToolsbooleantrueValidate tool calls against policy
quarantineToolOutputbooleantrueQuarantine tool outputs
onBlocked(error) => void--Called when input is blocked
onToolBlocked(toolName, result) => void--Called when a tool call is blocked

AegisChainGuard

Wraps agentic chain/agent execution with step-level protection. Enforces a step budget, tracks cumulative risk across steps, and terminates the chain if risk exceeds the threshold.

import { AegisChainGuard } from '@aegis-sdk/langchain';

const guard = new AegisChainGuard({
  aegis: new Aegis({ policy: 'strict' }),
  maxSteps: 10,
  riskThreshold: 0.7,
});

// In your agent loop:
const result = await guard.guardChainStep(currentMessages);
if (!result.allowed) {
  console.error('Chain terminated:', result.reason);
  break;
}
OptionTypeDefaultDescription
aegisAegisConfig | Aegis{}Aegis configuration or pre-constructed instance
maxStepsnumber25Maximum chain steps before termination
riskThresholdnumber0.8Cumulative risk score threshold (0-1)
scanStrategyScanStrategy"last-user"Which messages to scan per step
onBudgetExceeded(stepCount) => void--Called when step budget is exceeded
onRiskExceeded(cumulativeRisk) => void--Called when risk threshold is exceeded

Methods: guardChainStep(messages), getStepCount(), getCumulativeRisk(), getAegisInstance(), reset().

guardMessages(aegis, messages, options?)

Scans messages directly without using the callback handler. Throws AegisInputBlocked if input is blocked.

Re-exports

Aegis, AegisInputBlocked, AegisSessionQuarantined, AegisSessionTerminated, and all core types (including ActionValidationRequest, ActionValidationResult) are re-exported for convenience.

Learn More

License

MIT

FAQs

Package last updated on 24 Feb 2026

Did you know?

Socket

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.

Install

Related posts