{"_id":"@aegis-sdk/langchain","_rev":"3-30e891843eaca98e947b13a64f4fc5f2","name":"@aegis-sdk/langchain","dist-tags":{"latest":"0.5.0"},"versions":{"0.2.0":{"name":"@aegis-sdk/langchain","version":"0.2.0","license":"MIT","_id":"@aegis-sdk/langchain@0.2.0","maintainers":[{"name":"msjoshlopez","email":"josh@memberstack.com"}],"homepage":"https://github.com/aegis-sdk/aegis#readme","bugs":{"url":"https://github.com/aegis-sdk/aegis/issues"},"dist":{"shasum":"a8a123be07f9da32039d6a98c9b00cacb621fa4f","tarball":"https://registry.npmjs.org/@aegis-sdk/langchain/-/langchain-0.2.0.tgz","fileCount":8,"integrity":"sha512-s7f5SFRr6F3rd6uamoOVirlMQQANqVdJT7cGW7aXAT52Uarugzod+LydhydZq25I/NCiXrAzkNQnLIva1VsGKA==","signatures":[{"sig":"MEUCIDIOk9V3C/IEPtli690FOQZoMDc+ZyrMxYoBGDxZlr4jAiEAoJksmOjYL03xhs5we+LE5Bgyd6h9ZHMoUvun4b3Ti2A=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":93413},"main":"./dist/index.cjs","type":"module","_from":"file:aegis-sdk-langchain-0.2.0.tgz","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">=18.0.0"},"exports":{".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}}},"scripts":{"dev":"tsup --watch","build":"tsup","clean":"rm -rf dist","typecheck":"tsc --noEmit"},"_npmUser":{"name":"msjoshlopez","email":"josh@memberstack.com"},"_resolved":"/tmp/9db220052176fbb24284c071feb7d4a4/aegis-sdk-langchain-0.2.0.tgz","_integrity":"sha512-s7f5SFRr6F3rd6uamoOVirlMQQANqVdJT7cGW7aXAT52Uarugzod+LydhydZq25I/NCiXrAzkNQnLIva1VsGKA==","repository":{"url":"git+https://github.com/aegis-sdk/aegis.git","type":"git","directory":"packages/langchain"},"_npmVersion":"10.9.4","description":"LangChain.js adapter for Aegis prompt injection defense","directories":{},"sideEffects":false,"_nodeVersion":"22.22.0","dependencies":{"@aegis-sdk/core":"0.2.0"},"_hasShrinkwrap":false,"peerDependencies":{"langchain":">=0.1.0","@aegis-sdk/core":"0.2.0","@langchain/core":">=0.1.0"},"_npmOperationalInternal":{"tmp":"tmp/langchain_0.2.0_1771372100668_0.36639890729930946","host":"s3://npm-registry-packages-npm-production"}},"0.3.0":{"name":"@aegis-sdk/langchain","version":"0.3.0","license":"MIT","_id":"@aegis-sdk/langchain@0.3.0","maintainers":[{"name":"msjoshlopez","email":"josh@memberstack.com"}],"homepage":"https://github.com/aegis-sdk/aegis#readme","bugs":{"url":"https://github.com/aegis-sdk/aegis/issues"},"dist":{"shasum":"ede40e13a13bb2986415f5fc04e2b0a0ae616047","tarball":"https://registry.npmjs.org/@aegis-sdk/langchain/-/langchain-0.3.0.tgz","fileCount":8,"integrity":"sha512-Kn9fqS6uNPBZ1cmkuL9KPn8uDZSKqOT7zLnfQ0bG0i+IGe7cRXkqLkCHjpu1rr5iwTLHMDkSGnQ3Uh7+OgY1rQ==","signatures":[{"sig":"MEYCIQC+nhLIFijew9QncGdspEe2szWklPkrywv6Ax8Ui+s1SAIhAJVeart1TQxayDYtvrA4CPBYBenmUXwsAiJJftTR2Sdg","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":93413},"main":"./dist/index.cjs","type":"module","_from":"file:aegis-sdk-langchain-0.3.0.tgz","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">=18.0.0"},"exports":{".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}}},"scripts":{"dev":"tsup --watch","build":"tsup","clean":"rm -rf dist","typecheck":"tsc --noEmit"},"_npmUser":{"name":"msjoshlopez","email":"josh@memberstack.com"},"_resolved":"/tmp/a8db1404dfff65217861cd1ab34a7a63/aegis-sdk-langchain-0.3.0.tgz","_integrity":"sha512-Kn9fqS6uNPBZ1cmkuL9KPn8uDZSKqOT7zLnfQ0bG0i+IGe7cRXkqLkCHjpu1rr5iwTLHMDkSGnQ3Uh7+OgY1rQ==","repository":{"url":"git+https://github.com/aegis-sdk/aegis.git","type":"git","directory":"packages/langchain"},"_npmVersion":"10.9.4","description":"LangChain.js adapter for Aegis prompt injection defense","directories":{},"sideEffects":false,"_nodeVersion":"22.22.0","dependencies":{"@aegis-sdk/core":"0.3.0"},"_hasShrinkwrap":false,"peerDependencies":{"langchain":">=0.1.0","@aegis-sdk/core":"0.3.0","@langchain/core":">=0.1.0"},"_npmOperationalInternal":{"tmp":"tmp/langchain_0.3.0_1771394273204_0.20487275938775107","host":"s3://npm-registry-packages-npm-production"}},"0.5.0":{"name":"@aegis-sdk/langchain","version":"0.5.0","description":"LangChain.js adapter for Aegis prompt injection defense","license":"MIT","type":"module","exports":{".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}}},"main":"./dist/index.cjs","module":"./dist/index.js","types":"./dist/index.d.ts","peerDependencies":{"langchain":">=0.1.0","@langchain/core":">=0.1.0","@aegis-sdk/core":"0.5.0"},"dependencies":{"@aegis-sdk/core":"0.5.0"},"repository":{"type":"git","url":"git+https://github.com/aegis-sdk/aegis.git","directory":"packages/langchain"},"engines":{"node":">=18.0.0"},"sideEffects":false,"scripts":{"build":"tsup","dev":"tsup --watch","typecheck":"tsc --noEmit","clean":"rm -rf dist"},"_id":"@aegis-sdk/langchain@0.5.0","bugs":{"url":"https://github.com/aegis-sdk/aegis/issues"},"homepage":"https://github.com/aegis-sdk/aegis#readme","_integrity":"sha512-LofE0lLsd0qjQbFWFnieV4Rty1cdUjZ6h2DNHjJYnzVZscWpdlgNovNvCaYak/nXnZShIf589M0sFUbD1WsDlA==","_resolved":"/tmp/d189ba4e82b6d5710c6c18882f1ee8cc/aegis-sdk-langchain-0.5.0.tgz","_from":"file:aegis-sdk-langchain-0.5.0.tgz","_nodeVersion":"22.22.0","_npmVersion":"10.9.4","dist":{"integrity":"sha512-LofE0lLsd0qjQbFWFnieV4Rty1cdUjZ6h2DNHjJYnzVZscWpdlgNovNvCaYak/nXnZShIf589M0sFUbD1WsDlA==","shasum":"00689a836ac20677f934a6a5231cb03a11bf5424","tarball":"https://registry.npmjs.org/@aegis-sdk/langchain/-/langchain-0.5.0.tgz","fileCount":9,"unpackedSize":96894,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIEbPwytxX+IcZ9QYo9FWIPBl7GQjvpqviomWInvIoi85AiArCC7asDMwVph98JikwWgrRdNV2Sz6RIBnVhlhZ4LfrA=="}]},"_npmUser":{"name":"msjoshlopez","email":"josh@memberstack.com"},"directories":{},"maintainers":[{"name":"msjoshlopez","email":"josh@memberstack.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/langchain_0.5.0_1771972389523_0.19525515527163417"},"_hasShrinkwrap":false}},"time":{"created":"2026-02-17T23:48:20.563Z","modified":"2026-02-24T22:33:09.792Z","0.2.0":"2026-02-17T23:48:20.800Z","0.3.0":"2026-02-18T05:57:53.338Z","0.5.0":"2026-02-24T22:33:09.662Z"},"bugs":{"url":"https://github.com/aegis-sdk/aegis/issues"},"license":"MIT","homepage":"https://github.com/aegis-sdk/aegis#readme","repository":{"type":"git","url":"git+https://github.com/aegis-sdk/aegis.git","directory":"packages/langchain"},"description":"LangChain.js adapter for Aegis prompt injection defense","maintainers":[{"name":"msjoshlopez","email":"josh@memberstack.com"}],"readme":"# @aegis-sdk/langchain\n\nLangChain.js callback handler and chain guard for prompt injection defense.\n\nPart of the [Aegis.js](https://github.com/aegis-sdk/Aegis) prompt injection defense toolkit.\n\n## Installation\n\n```bash\nnpm install @aegis-sdk/langchain @aegis-sdk/core\n```\n\n## Quick Start\n\n```ts\nimport { ChatOpenAI } from '@langchain/openai';\nimport { Aegis } from '@aegis-sdk/core';\nimport { createAegisCallback } from '@aegis-sdk/langchain';\n\nconst aegis = new Aegis({ policy: 'strict' });\n\nconst model = new ChatOpenAI({\n  callbacks: [createAegisCallback(aegis)],\n});\n\nconst result = await model.invoke('Hello!');\n```\n\n## API\n\n### `createAegisCallback(optionsOrAegis?)`\n\nCreates a LangChain-compatible callback handler that intercepts LLM and tool lifecycle events:\n\n- **`handleLLMStart`** -- Scans input prompts for injection patterns\n- **`handleLLMEnd`** -- Quarantines LLM output for safe downstream consumption\n- **`handleToolStart`** -- Validates tool calls against the Aegis policy\n- **`handleToolEnd`** -- Quarantines tool output\n\nAccepts an `Aegis` instance, `AegisConfig`, or `AegisCallbackOptions`:\n\n| Option | Type | Default | Description |\n|---|---|---|---|\n| `aegis` | `AegisConfig \\| Aegis` | `{}` | Aegis configuration or pre-constructed instance |\n| `scanInput` | `boolean` | `true` | Scan LLM input prompts |\n| `scanOutput` | `boolean` | `true` | Scan LLM output for violations |\n| `validateTools` | `boolean` | `true` | Validate tool calls against policy |\n| `quarantineToolOutput` | `boolean` | `true` | Quarantine tool outputs |\n| `onBlocked` | `(error) => void` | -- | Called when input is blocked |\n| `onToolBlocked` | `(toolName, result) => void` | -- | Called when a tool call is blocked |\n\n### `AegisChainGuard`\n\nWraps 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.\n\n```ts\nimport { AegisChainGuard } from '@aegis-sdk/langchain';\n\nconst guard = new AegisChainGuard({\n  aegis: new Aegis({ policy: 'strict' }),\n  maxSteps: 10,\n  riskThreshold: 0.7,\n});\n\n// In your agent loop:\nconst result = await guard.guardChainStep(currentMessages);\nif (!result.allowed) {\n  console.error('Chain terminated:', result.reason);\n  break;\n}\n```\n\n| Option | Type | Default | Description |\n|---|---|---|---|\n| `aegis` | `AegisConfig \\| Aegis` | `{}` | Aegis configuration or pre-constructed instance |\n| `maxSteps` | `number` | `25` | Maximum chain steps before termination |\n| `riskThreshold` | `number` | `0.8` | Cumulative risk score threshold (0-1) |\n| `scanStrategy` | `ScanStrategy` | `\"last-user\"` | Which messages to scan per step |\n| `onBudgetExceeded` | `(stepCount) => void` | -- | Called when step budget is exceeded |\n| `onRiskExceeded` | `(cumulativeRisk) => void` | -- | Called when risk threshold is exceeded |\n\nMethods: `guardChainStep(messages)`, `getStepCount()`, `getCumulativeRisk()`, `getAegisInstance()`, `reset()`.\n\n### `guardMessages(aegis, messages, options?)`\n\nScans messages directly without using the callback handler. Throws `AegisInputBlocked` if input is blocked.\n\n### Re-exports\n\n`Aegis`, `AegisInputBlocked`, `AegisSessionQuarantined`, `AegisSessionTerminated`, and all core types (including `ActionValidationRequest`, `ActionValidationResult`) are re-exported for convenience.\n\n## Learn More\n\n- [Documentation](https://aegis-sdk.github.io/Aegis/)\n- [GitHub](https://github.com/aegis-sdk/Aegis)\n\n## License\n\nMIT\n","readmeFilename":"README.md"}