{"_id":"@coralogix/guardrails-langchain","_rev":"7-b62ca1d215c4b1d5ec0ca89340674903","name":"@coralogix/guardrails-langchain","dist-tags":{"latest":"0.6.0"},"versions":{"0.2.0":{"name":"@coralogix/guardrails-langchain","version":"0.2.0","keywords":["Coralogix","Guardrails","AI"],"author":{"name":"Coralogix"},"license":"Apache-2.0","_id":"@coralogix/guardrails-langchain@0.2.0","maintainers":[{"name":"coralogixnpm","email":"npm@coralogix.com"}],"dist":{"shasum":"84ebdf6ddd08d6238a9a2f1a656d65a9e2806e94","tarball":"https://registry.npmjs.org/@coralogix/guardrails-langchain/-/guardrails-langchain-0.2.0.tgz","fileCount":7,"integrity":"sha512-a1grR0qUG6o5IfegW5btF8D19Cp1Y0Jb00Eh70euYUrGrQVRl74IwZYldBmzL7dpq1dU3iCVh9H44lYxyg8Y4A==","signatures":[{"sig":"MEUCIQCE4nNW39ijgfmSV1RixgEqBXWhlZ73sAUrTJjMVN5UsAIgcQ6Ef8EfB7SMXA0zVS7UsKUpFY9GWjZpIFHkcDBRgak=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":33672},"main":"./dist/index.js","type":"module","_from":"file:coralogix-guardrails-langchain-0.2.0.tgz","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":"./dist/index.js","./package.json":"./package.json"},"scripts":{"eval":"tsx eval.tsx","build":"tsdown","example":"tsx example.ts"},"_npmUser":{"name":"coralogixnpm","email":"npm@coralogix.com"},"_resolved":"/tmp/e46b9d46077f970d9c7d8ac4c5774200/coralogix-guardrails-langchain-0.2.0.tgz","_integrity":"sha512-a1grR0qUG6o5IfegW5btF8D19Cp1Y0Jb00Eh70euYUrGrQVRl74IwZYldBmzL7dpq1dU3iCVh9H44lYxyg8Y4A==","_npmVersion":"10.8.2","description":"AI Guardrails Langchain TypeScript adapter","directories":{},"_nodeVersion":"20.19.4","dependencies":{"ink":"^6.0.1","tsx":"^4.20.3","zod":"^4.0.13","react":"^19.1.0","dotenv":"^16.4.7","@types/node":"^24.0.15","@types/react":"^19.1.8","@langchain/core":"^0.3.64","@langchain/openai":"^0.6.9","@langchain/langgraph":"^0.3.10"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsdown":"^0.14.2","typescript":"^5.9.2"},"_npmOperationalInternal":{"tmp":"tmp/guardrails-langchain_0.2.0_1756817705360_0.6814808990922445","host":"s3://npm-registry-packages-npm-production"}},"0.3.0":{"name":"@coralogix/guardrails-langchain","version":"0.3.0","keywords":["Coralogix","Guardrails","AI"],"author":{"name":"Coralogix"},"license":"Apache-2.0","_id":"@coralogix/guardrails-langchain@0.3.0","maintainers":[{"name":"coralogixnpm","email":"npm@coralogix.com"}],"dist":{"shasum":"98963f813a1aa3a0511cfc05788f93178b9d1392","tarball":"https://registry.npmjs.org/@coralogix/guardrails-langchain/-/guardrails-langchain-0.3.0.tgz","fileCount":7,"integrity":"sha512-8UXwxWF68bDyMp9BkrLEaNVtyt3N24Sbqk56yp+bOsXnEKytU6fQBeHu/S/omBb8ZcNhuooLajJvlbDoD6Mrlw==","signatures":[{"sig":"MEUCIQDCW+jctE77j/boTLn404oLzebieiR0lFEVNBTYIejg/AIgBgKIyEZIfaBzOF2vWWTqBFIcEKnrVK8q3MYrvp5fUL4=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":33672},"main":"./dist/index.js","type":"module","_from":"file:coralogix-guardrails-langchain-0.3.0.tgz","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":"./dist/index.js","./package.json":"./package.json"},"scripts":{"eval":"tsx eval.tsx","build":"tsdown","example":"tsx example.ts"},"_npmUser":{"name":"coralogixnpm","email":"npm@coralogix.com"},"_resolved":"/tmp/eefa95ecbc951f45fd8ed306f0f7b934/coralogix-guardrails-langchain-0.3.0.tgz","_integrity":"sha512-8UXwxWF68bDyMp9BkrLEaNVtyt3N24Sbqk56yp+bOsXnEKytU6fQBeHu/S/omBb8ZcNhuooLajJvlbDoD6Mrlw==","_npmVersion":"10.8.2","description":"AI Guardrails Langchain TypeScript adapter","directories":{},"_nodeVersion":"20.19.4","dependencies":{"ink":"^6.0.1","tsx":"^4.20.3","zod":"^4.0.13","react":"^19.1.0","dotenv":"^16.4.7","@types/node":"^24.0.15","@types/react":"^19.1.8","@langchain/core":"^0.3.64","@langchain/openai":"^0.6.9","@langchain/langgraph":"^0.3.10"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsdown":"^0.14.2","typescript":"^5.9.2"},"_npmOperationalInternal":{"tmp":"tmp/guardrails-langchain_0.3.0_1756819413111_0.038606755111415536","host":"s3://npm-registry-packages-npm-production"}},"0.4.0":{"name":"@coralogix/guardrails-langchain","version":"0.4.0","keywords":["Coralogix","Guardrails","AI"],"author":{"name":"Coralogix"},"license":"Apache-2.0","_id":"@coralogix/guardrails-langchain@0.4.0","maintainers":[{"name":"coralogixnpm","email":"npm@coralogix.com"}],"homepage":"https://github.com/coralogix/guardrails-langchain-ts-adapter#readme","bugs":{"url":"https://github.com/coralogix/guardrails-langchain-ts-adapter/issues","email":"support@coralogix.com"},"dist":{"shasum":"903b55811a9e64788221a61826b2cf15fc14c265","tarball":"https://registry.npmjs.org/@coralogix/guardrails-langchain/-/guardrails-langchain-0.4.0.tgz","fileCount":7,"integrity":"sha512-dq3mDs9pErZ3Z/1rZy6Mcf9iOQEKa6+fM5x/dcIO1cDTUqfWJa0wh0OnwzX0PBxlUP6N7tZtEqmrklYp3Dlw8Q==","signatures":[{"sig":"MEUCICEMaPRZLAfvg5L+rKBp+9KoTvt1nywdb0X+JqGofkMLAiEAx5R1hl7zzECps2LMBkc5ek39+9ftXhtlH8DPLQXmXow=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":34043},"main":"./dist/index.js","type":"module","_from":"file:coralogix-guardrails-langchain-0.4.0.tgz","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":"./dist/index.js","./package.json":"./package.json"},"scripts":{"eval":"tsx eval.tsx","build":"tsdown","example":"tsx example.ts"},"_npmUser":{"name":"coralogixnpm","email":"npm@coralogix.com"},"_resolved":"/tmp/957678b3ca6234b68ae141609fc5fb13/coralogix-guardrails-langchain-0.4.0.tgz","_integrity":"sha512-dq3mDs9pErZ3Z/1rZy6Mcf9iOQEKa6+fM5x/dcIO1cDTUqfWJa0wh0OnwzX0PBxlUP6N7tZtEqmrklYp3Dlw8Q==","_npmVersion":"10.8.2","description":"AI Guardrails Langchain TypeScript adapter","directories":{},"_nodeVersion":"20.19.5","dependencies":{"zod":"^4.0.13","@langchain/core":"^0.3.64","@langchain/openai":"^0.6.9","@langchain/langgraph":"^0.3.10"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"ink":"^6.0.1","tsx":"^4.20.3","react":"^19.1.0","dotenv":"^16.4.7","tsdown":"^0.14.2","typescript":"^5.9.2","@types/node":"^24.0.15","@types/react":"^19.1.8"},"_npmOperationalInternal":{"tmp":"tmp/guardrails-langchain_0.4.0_1758788595221_0.16547415241103947","host":"s3://npm-registry-packages-npm-production"}},"0.5.0":{"name":"@coralogix/guardrails-langchain","version":"0.5.0","keywords":["Coralogix","Guardrails","AI"],"author":{"name":"Coralogix"},"license":"Apache-2.0","_id":"@coralogix/guardrails-langchain@0.5.0","maintainers":[{"name":"coralogixnpm","email":"npm@coralogix.com"}],"homepage":"https://github.com/coralogix/guardrails-langchain-ts-adapter#readme","bugs":{"url":"https://github.com/coralogix/guardrails-langchain-ts-adapter/issues","email":"support@coralogix.com"},"dist":{"shasum":"8d6315e1d40f51ab681683dbd71662ec212d0f97","tarball":"https://registry.npmjs.org/@coralogix/guardrails-langchain/-/guardrails-langchain-0.5.0.tgz","fileCount":7,"integrity":"sha512-ZU61XVsm8FH9WoWIEoYj8Psk5LYAElR+LCI2/Tlm7Njf2vAw60JyQhbOVWnhJg6zkhDw/7HfwTMKa5P4pGkOzA==","signatures":[{"sig":"MEYCIQD2MP8QbJ+3+oRrxH2QC35MlbXTkB+odeTyHICwfW62zwIhAPvHvUoIiB3QBSDYjXGa483Bzj9X3Lv8j6BtTfRwe6Oq","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":35145},"main":"./dist/index.js","type":"module","_from":"file:coralogix-guardrails-langchain-0.5.0.tgz","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":"./dist/index.js","./package.json":"./package.json"},"scripts":{"eval":"tsx eval.tsx","build":"tsdown","example":"tsx example.ts"},"_npmUser":{"name":"coralogixnpm","email":"npm@coralogix.com"},"_resolved":"/tmp/fc82f8a0ae8508e1cf4cda1cc370c766/coralogix-guardrails-langchain-0.5.0.tgz","_integrity":"sha512-ZU61XVsm8FH9WoWIEoYj8Psk5LYAElR+LCI2/Tlm7Njf2vAw60JyQhbOVWnhJg6zkhDw/7HfwTMKa5P4pGkOzA==","_npmVersion":"10.8.2","description":"AI Guardrails Langchain TypeScript adapter","directories":{},"_nodeVersion":"20.19.5","dependencies":{"zod":"^4.0.13","@langchain/core":"^0.3.64","@langchain/openai":"^0.6.9","@langchain/langgraph":"^0.3.10"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"ink":"^6.0.1","tsx":"^4.20.3","react":"^19.1.0","dotenv":"^16.4.7","tsdown":"^0.14.2","typescript":"^5.9.2","@types/node":"^24.0.15","@types/react":"^19.1.8"},"_npmOperationalInternal":{"tmp":"tmp/guardrails-langchain_0.5.0_1761227736697_0.9226009444560375","host":"s3://npm-registry-packages-npm-production"}},"0.6.0":{"name":"@coralogix/guardrails-langchain","version":"0.6.0","keywords":["Coralogix","Guardrails","AI"],"author":{"name":"Coralogix"},"license":"Apache-2.0","_id":"@coralogix/guardrails-langchain@0.6.0","maintainers":[{"name":"coralogixnpm","email":"npm@coralogix.com"}],"homepage":"https://github.com/coralogix/guardrails-langchain-ts-adapter#readme","bugs":{"url":"https://github.com/coralogix/guardrails-langchain-ts-adapter/issues","email":"support@coralogix.com"},"dist":{"shasum":"2abd0df71f1db2825d2e2367bc051608fa42ced5","tarball":"https://registry.npmjs.org/@coralogix/guardrails-langchain/-/guardrails-langchain-0.6.0.tgz","fileCount":7,"integrity":"sha512-v4Dw3hcRfje1KBGxUvi6wVU08ncJT6kmHD2W5k4OZMp/X58yyMPR1wTBR4R20p3uzQJsWZ2k3tKj9GwvpJDliA==","signatures":[{"sig":"MEYCIQDM4v5n/zmL92hwxQYSJNFAUD5MAebau/ZFOyKuRnMYfQIhAK4i3xIy+3f2an4oC/90Z+zInkhngcvQegj3IXT9SM6+","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":33842},"main":"./dist/index.cjs","type":"module","_from":"file:coralogix-guardrails-langchain-0.6.0.tgz","types":"./dist/index.d.mts","module":"./dist/index.mjs","exports":{".":{"import":"./dist/index.mjs","require":"./dist/index.cjs"},"./package.json":"./package.json"},"scripts":{"eval":"tsx eval.tsx","build":"tsdown","example":"tsx example.ts"},"_npmUser":{"name":"coralogixnpm","email":"npm@coralogix.com"},"_resolved":"/tmp/ccc2bcec69a687d4edd7b8003e6cb2cd/coralogix-guardrails-langchain-0.6.0.tgz","_integrity":"sha512-v4Dw3hcRfje1KBGxUvi6wVU08ncJT6kmHD2W5k4OZMp/X58yyMPR1wTBR4R20p3uzQJsWZ2k3tKj9GwvpJDliA==","_npmVersion":"10.8.2","description":"AI Guardrails Langchain TypeScript adapter","directories":{},"_nodeVersion":"20.20.0","dependencies":{"zod":"^4.3.6"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"ink":"^6.0.1","tsx":"^4.20.3","react":"^19.1.0","dotenv":"^16.4.7","tsdown":"^0.20.3","typescript":"^5.9.2","@types/node":"^24.0.15","@types/react":"^19.1.8","@langchain/core":"1.1.19","@langchain/openai":"1.2.0","@langchain/langgraph":"^1.1.4"},"peerDependencies":{"@langchain/core":">=1.1.0 <2","@langchain/openai":">=1.2.0 <2","@langchain/langgraph":">=1.0.0 <2"},"peerDependenciesMeta":{"@langchain/langgraph":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/guardrails-langchain_0.6.0_1771175915795_0.1992967210576857","host":"s3://npm-registry-packages-npm-production"}}},"time":{"created":"2025-09-02T12:55:05.286Z","modified":"2026-06-29T13:51:04.196Z","0.2.0":"2025-09-02T12:55:05.533Z","0.3.0":"2025-09-02T13:23:33.291Z","0.4.0":"2025-09-25T08:23:15.405Z","0.5.0":"2025-10-23T13:55:36.870Z","0.6.0":"2026-02-15T17:18:35.925Z"},"bugs":{"url":"https://github.com/coralogix/guardrails-langchain-ts-adapter/issues","email":"support@coralogix.com"},"author":{"name":"Coralogix"},"license":"Apache-2.0","homepage":"https://github.com/coralogix/guardrails-langchain-ts-adapter#readme","keywords":["Coralogix","Guardrails","AI"],"description":"AI Guardrails Langchain TypeScript adapter","maintainers":[{"email":"npm@coralogix.com","name":"coralogixnpm"},{"email":"ashley.hunter@coralogix.com","name":"ashley-hunter-cx"},{"email":"shahar.kazaz@coralogix.com","name":"cx-shaharkazaz"}],"readme":"# LangChain Aporia Guardrails Integration\n\nA TypeScript wrapper that adds Aporia Guardrails to any LangChain `BaseChatModel`, enabling real-time content filtering and safety controls for both prompts and responses.\n\n## Installation\n\n```bash\nnpm install\n```\n\n## Configuration\n\n### Environment Variables\n\nCreate a `.env` file in the project root with your API keys:\n\n```bash\n# Aporia Guardrails Configuration\nAPORIA_PROJECT_ID=your_project_id_here\nAPORIA_API_KEY=your_api_key_here\n\n# OpenAI API Key\nOPENAI_API_KEY=your_openai_api_key_here\n\n# Alternatively, to use Azure OpenAI:\n# AZURE_OPENAI_API_KEY=your_azure_openai_api_key_here\n# AZURE_OPENAI_API_INSTANCE_NAME=your_azure_openapi_api_instance_name_here\n# AZURE_OPENAI_API_DEPLOYMENT_NAME=your_azure_openai_api_deployment_name_here\n# AZURE_OPENAI_API_VERSION=your_azure_openapi_api_version_here\n```\n\nYou'll need:\n- **Aporia Project ID**: Your Aporia guardrails project identifier\n- **Aporia API Key**: Authentication key for the Aporia service\n- **OpenAI / Azure OpenAI auth details**: Your OpenAI / Azure OpenAI API key for the language model\n\n## Quick Start\n\nAfter setting up your `.env` file, you can run the examples:\n\n```bash\n# Run the basic example\nnpm run example\n```\n\nFor Azure OpenAI, please uncomment the relevant section in `example.ts`.\n\n## Usage\n\n### Basic Example\n\n```typescript\nimport { ChatOpenAI } from \"@langchain/openai\";\nimport { HumanMessage } from \"@langchain/core/messages\";\nimport { withGuardrails } from \"@coralogix/guardrails-langchain\";\n\n// Create your base model\nconst model = new ChatOpenAI({\n  model: \"gpt-4o-2024-11-20\",\n  temperature: 0,\n  configuration: {\n    apiKey: \"your-openai-api-key\"\n  }\n});\n\n// Wrap with guardrails\nconst guardedModel = withGuardrails(model, {\n  projectId: \"your-aporia-project-id\",\n  apiKey: \"your-aporia-api-key\"\n});\n\n// Use the model normally - guardrails are applied automatically\nconst response = await guardedModel.invoke([\n  new HumanMessage(\"Hello, how can you help me today?\")\n]);\n\nconsole.log(response.content);\n```\n\n### Streaming Example\n\n```typescript\nconst guardedModel = withGuardrails(model, {\n  projectId: \"your-aporia-project-id\",\n  apiKey: \"your-aporia-api-key\",\n  chunkBatchSize: 25  // Check guardrails every 25 chunks (default: 50)\n});\n\n// Optionally override the Aporia Guardrails base URL (default: https://gr-prd.aporia.com)\nconst guardedModelWithCustomBase = withGuardrails(model, {\n  projectId: \"your-aporia-project-id\",\n  apiKey: \"your-aporia-api-key\",\n  baseUrl: \"https://gr-prd-eu.example.com\",\n  chunkBatchSize: 25\n});\n\nconst stream = await guardedModel.stream([\n  new HumanMessage(\"Tell me a story about space exploration\")\n]);\n\nfor await (const chunk of stream) {\n  process.stdout.write(chunk.content);\n}\n```\n\n### Advanced Configuration\n\n```typescript\nimport type { AporiaGuardrailsConfig } from \"@coralogix/guardrails-langchain\";\n\nconst config: AporiaGuardrailsConfig = {\n  projectId: \"your-project-id\",\n  apiKey: \"your-api-key\",\n  chunkBatchSize: 100,  // Optional: check every 100 chunks instead of default 200\n  // Optional: override the Aporia Guardrails API base URL (defaults to https://gr-prd.aporia.com)\n  baseUrl: \"https://gr-prd-eu.example.com\"\n};\n\nconst guardedModel = withGuardrails(model, config);\n```\n\n## Configuration Options\n\n| Property | Type | Required | Default | Description |\n|----------|------|----------|---------|-------------|\n| `projectId` | `string` | ✅ | - | Your Aporia guardrails project ID |\n| `apiKey` | `string` | ✅ | - | Your Aporia API key |\n| `chunkBatchSize` | `number` | ❌ | `200` | How often to check guardrails during streaming (every N chunks) |\n| `baseUrl` | `string` | ❌ | `https://gr-prd.aporia.com` | Optional base URL for the Aporia Guardrails API |\n\n## How It Works\n\n1. **Prompt Validation**: Before sending to the model, user prompts are validated against your guardrail policies\n2. **Response Validation**: Model responses are checked before being returned to the user\n3. **Streaming Validation**: During streaming, content is validated in configurable batches\n4. **Action Handling**: Based on guardrail responses, content can be:\n   - `passthrough` - Allow content unchanged\n   - `block` - Block content with override message\n   - `modify` - Replace with suggested alternative\n   - `rephrase` - Replace with rephrased version\n\n## Error Handling\n\nThe wrapper handles guardrail API failures gracefully:\n- Network errors are thrown as exceptions\n- Invalid responses are validated with Zod schemas\n- Failed guardrail checks return override messages\n\n## Types\n\n```typescript\ninterface AporiaGuardrailsConfig {\n  projectId: string;\n  apiKey: string;\n  chunkBatchSize?: number;\n}\n\ntype GuardrailsResponse = {\n  action: \"modify\" | \"passthrough\" | \"block\" | \"rephrase\";\n  revised_response: string | null;\n  // ... other fields allowed\n}\n```\n","readmeFilename":"README.md"}