Frameworks
Any chatbot or agent
The universal pattern for when no framework-specific guide applies.
About 5 minutes hands-on
What this guide does not cover
- A pattern, not a runnable app. You supply the transport, session handling, and model call.
- If a framework-specific guide exists for your stack, use it instead — this is the fallback.
Step 1: Install the SDK
Terminal
npm install @soterai/coreStep 2: Basic chatbot pattern
TypeScript
1import { Soter } from "@soterai/core";
2
3const soter = new Soter({
4 apiKey: process.env.SOTER_API_KEY,
5});
6
7// Guard input → call LLM → guard output
8const result = await soter.protect({
9 input: userMessage,
10 context: { userId: "user_123", sessionId: "session_123" },
11});
12
13if (!result.allowed) {
14 // 🛑 Blocked before LLM
15 return { reply: "Message blocked.", blocked: true };
16}
17
18const llmReply = await callLLM(result.safeText ?? userMessage);
19const outputResult = await soter.guardOutput({ text: llmReply });
20
21return {
22 reply: outputResult.safeText ?? outputResult.redactedText ?? llmReply,
23 blocked: !outputResult.allowed,
24};Step 3: Agent with tool firewall
For agents that call tools, APIs, or access data:
TypeScript
1import { Soter, createAgentFirewallClient } from "@soterai/core";
2
3const soter = new Soter({
4 apiKey: process.env.SOTER_API_KEY,
5});
6
7const firewall = createAgentFirewallClient({
8 apiKey: process.env.SOTER_API_KEY,
9});
10
11// Start an agent session
12const session = await firewall.startAgentSession({
13 agentName: "support-bot",
14 agentType: "chatbot",
15});
16
17// Check every tool call before execution
18const action = await firewall.checkAgentAction({
19 sessionId: session.sessionId,
20 tool: "api.call",
21 action: "post_ticket",
22 content: ticketPayload,
23 destination: "external",
24 riskContext: { externalDestination: true, canModifyData: true },
25});
26
27if (action.decision === "BLOCK") return action.reason;
28if (action.decision === "ASK_APPROVAL") {
29 return action.requiredApproval?.message;
30}
31
32// Only execute after firewall allows it
33const toolResult = await callTool(action.safeContent ?? ticketPayload);
34
35// Guard the final output before returning it
36const final = await soter.guardOutput({ text: toolResult });
37return final.safeText ?? final.redactedText ?? toolResult;Key rules
Approve tools first
Never execute a tool before the firewall approves it.
Guard both ways
Always guard both input and output, not just one.
Use retries
Set retries: 2 for transient error tolerance.
Keep API key server-side
Never expose the API key in browser or mobile code.
This reduces risk; it does not guarantee complete protection.