Feature — Guardrails

Stop bad outputs before they reach users.

7 guardrail types run inline on every LLM request — block, warn, redact, or log. PII, toxicity, topic drift, format, cost ceiling, and custom rules.

Pre-call and post-call phases. Configurable per agent. Live test before deploying.

zespan.com — guardrails
Zespan Guardrails
Works withPre-call phasePost-call phaseAgent filterRegexLLM judgePII redaction

7

types

4

actions

50ms

min latency cap

7 Guardrail Types

PII detects and redacts personal data. Toxicity blocks harmful content. Topic boundary prevents scope creep. Format enforces output structure. Cost ceiling blocks expensive requests. Custom LLM uses your own judge prompt. Regex handles exact pattern matching.

  • PII, Toxicity, Topic Boundary, Format, Cost Ceiling, Custom LLM, Regex
  • Phase: pre (before LLM call), post (after response), or both
  • Priority 0–100: controls execution order when multiple guardrails apply
7 guardrail types
Zespan guardrail configuration showing types, actions, and phase settings

4 Actions: Block, Warn, Redact, Log

Block rejects the request and returns a GuardrailBlockedError. Warn logs the issue and allows through. Redact removes matching content and allows the modified text through. Log records without interfering.

  • Block: throws GuardrailBlockedError — handle in your catch block
  • Redact: matching content removed, modified text returned in result.modifiedText
  • Warn / Log: zero user-visible impact, full audit trail

Live Test Before Deploying

Pass any draft guardrail config and arbitrary input text to the live test endpoint — no save required, no deployment needed. See exactly what would be blocked, warned, or redacted before it goes live.

  • Test with draft config: preview guardrail behavior without saving
  • Apply guardrails in Playground: validate prompt safety interactively
  • Per-guardrail latency cap (50ms–30s): slow guards never block requests

Execution Logs & Metrics

Every guardrail check is logged: slug, passed/failed, action taken, reason, modified text, and latency. Time-range metrics (pass/block/warn/redact rates) available for 24h, 7d, 30d. All config changes written to audit log.

  • Per-check log: queryable by guardrail ID, result, and time range
  • Result caching: repeated identical inputs skip re-evaluation via CacheLayer
  • Audit log: create/update/enable/disable events with actor user ID and IP

Get started

Set up in under 5 minutes

typescriptGuardrails
import { Zespan } from '@zespan/sdk';

const lt = new Zespan({ apiKey: process.env.ZESPAN_API_KEY });

// Guardrail check — configured in dashboard, enforced by SDK
try {
  const result = await lt.guardrails.check({
    input: userMessage,
    projectId: 'your-project-id',
  });
  // result.passed, result.action, result.modifiedText
} catch (err) {
  if (err instanceof GuardrailBlockedError) {
    return { blocked: true, reason: err.reason };
  }
}

Frequently asked

Do guardrails add latency to my LLM calls?

Only pre-call guardrails add latency — they run before the LLM call. Post-call guardrails run after and don't affect your response time. For pre-call guards, you can configure a max latency cap (50ms–30s) so a slow guardrail never blocks the request.

What happens when a guardrail blocks a request?

The SDK throws a GuardrailBlockedError with a reason field. Catch this error in your application and handle it — return a fallback response, log it, or show the user an appropriate message.

Can I scope a guardrail to only apply to certain agents?

Yes. Each guardrail has an agent filter field — set it to specific agent names and that guardrail only runs for those agents. Different agents can have different safety rules on the same project.

What's the difference between a custom LLM guardrail and a regex guardrail?

Regex guardrails use pattern matching — they're fast (sub-millisecond) and deterministic, ideal for exact strings, known PII formats, or prohibited phrases. Custom LLM guardrails use an LLM as judge — slower but understand context, semantics, and nuance. Use regex for rules you can fully specify; use custom LLM for rules that require judgment.

Are guardrail results cached?

Yes. Guardrail results are cached by input hash via CacheLayer. If the same input is seen again, Zespan returns the cached result without re-running the check — saving latency and LLM judge costs on repeated inputs.

Start free — 10K traces/month, no card needed

Setup takes under 5 minutes. Works with OpenAI, Anthropic, LangChain, and more.