npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@aegis-sdk/langchain

v0.5.0

Published

LangChain.js adapter for Aegis prompt injection defense

Readme

@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:

| Option | Type | Default | Description | |---|---|---|---| | aegis | AegisConfig \| Aegis | {} | Aegis configuration or pre-constructed instance | | scanInput | boolean | true | Scan LLM input prompts | | scanOutput | boolean | true | Scan LLM output for violations | | validateTools | boolean | true | Validate tool calls against policy | | quarantineToolOutput | boolean | true | Quarantine 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;
}

| Option | Type | Default | Description | |---|---|---|---| | aegis | AegisConfig \| Aegis | {} | Aegis configuration or pre-constructed instance | | maxSteps | number | 25 | Maximum chain steps before termination | | riskThreshold | number | 0.8 | Cumulative risk score threshold (0-1) | | scanStrategy | ScanStrategy | "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