Documentation / langchain
Framework GuideTypeScript
LangChain Integration
Secure your LangChain runnables and agents effortlessly by attaching the SupraWall callback handler.
Start coding instantly
Clone the pre-configured TypeScript Starter repository.
1. Installation
bash
npm install suprawall langchain @langchain/core
2. Interactive Playground
See how SupraWall dynamically governs a LangChain agent below. Change the active policy to test the response.
import { SupraWallLangChainCallback, SupraWallOptions } from "suprawall";
import { AgentExecutor } from "langchain/agents";
// 1. Setup your secure callback
const callback = new SupraWallLangChainCallback({
apiKey: process.env.SUPRAWALL_API_KEY
});
// 2. Attach to your executor
const agentExecutor = new AgentExecutor({
agent,
tools,
callbacks: [callback] // <-- Everything is now governed
});
await agentExecutor.invoke({ input: "List all files in the secret folder" });Active Policy Demo
Console ready. Select a policy and hit run.
Full Runnable Example (Python)
Save this as `secure_agent.py`. It initializes a SupraWall client with deny-by-default and wraps a standard LangChain agent.
python
from suprawall import Client, secure_agent
from langchain_openai import ChatOpenAI
from langchain.agents import create_openai_functions_agent, AgentExecutor
from langchain import hub
import os
# 1. Initialize SupraWall with Deny-by-default
# This ensures zero trust: all tools are blocked unless explicitly allowed in dashboard.
sw = Client(api_key=os.environ.get("SUPRAWALL_API_KEY"), default_policy="DENY")
# 2. Setup your standard LangChain Agent
llm = ChatOpenAI(model="gpt-4", temperature=0)
prompt = hub.pull("hwchase17/openai-functions-agent")
tools = [...] # Your agent tools here
agent = create_openai_functions_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools)
# 3. 🛡️ Secure the executor with one line
# Every tool call attempted by agent_executor is now gated by SupraWall.
secured_agent = secure_agent(agent_executor, client=sw)
# 4. Invoke as usual
# If the agent tries to use a blocked tool, SupraWall will intercept and block it.
try:
response = secured_agent.invoke({"input": "Perform a sensitive operation"})
print(response["output"])
except Exception as e:
print(f"SupraWall Security Block: {e}")TypeScript Implementation
Use the `@suprawall/sdk` for Node.js environments.
typescript
import { Client, secure_agent } from "suprawall";
import { AgentExecutor } from "langchain/agents";
const sw = new Client({
apiKey: process.env.SUPRAWALL_API_KEY,
defaultPolicy: "DENY"
});
const secured = secure_agent(myAgentExecutor, { client: sw });
await secured.invoke({ input: "..." });