Skip to main content
This guide will have you running guardrails in under five minutes. You’ll learn how to install the SDK, validate your first piece of content, and understand the result.

Before You Begin

You need an ABV API key to use guardrails. Sign up at app.abv.dev and create a new API key from your account settings.

Installation

Install the ABV client library for your language:
npm install @abvdev/client

Your First Validation

Let’s check if a user message contains toxic content. This is one of the most common uses of guardrails since it protects both your LLM from poisoned context and your users from harmful responses.
import { ABVClient } from "@abvdev/client";

// Initialize the client with your API key
const abv = new ABVClient({
  apiKey: process.env.ABV_API_KEY,
});

// Check a user message for toxic content
const result = await abv.guardrails.toxicLanguage.validate(
  "I really disagree with your approach to this problem.",
  { sensitivity: "medium" }
);

// The result tells you if the content passed or failed
console.log("Status:", result.status);        // "pass", "fail", or "unsure"
console.log("Confidence:", result.confidence); // 0.0 to 1.0
console.log("Reason:", result.reason);        // Explanation of the decision
The message in this example expresses disagreement but does so professionally, so it should pass with high confidence. Try changing the message to something more hostile and see how the result changes.

Understanding What Just Happened

You sent content to the guardrail

Your code called the toxic language guardrail with the message text and a sensitivity setting of “medium”. This sensitivity level catches clear violations while allowing professional disagreement.

The guardrail analyzed the content

The guardrail used an LLM to understand the context, tone, and intent of the message. Unlike keyword filters, it understands that “I disagree” is different from “You’re an idiot.”

You received a structured result

The result contains three key pieces: status (pass/fail/unsure), confidence (0.0-1.0), and reason (human-readable explanation). This structure is consistent across all guardrails.

ABV automatically created an observation

Without any additional code, the guardrail check was logged to your ABV dashboard. You can now view the input, output, confidence score, and timing information.

You can make decisions based on the result

Your application can now decide what to do: allow the content if it passed, block it if it failed, or flag it for human review if the guardrail was unsure.

Making Decisions with Results

You’ll typically use the status field to make decisions in your code:
if (result.status === "pass") {
  // Content is safe, continue processing
  await processUserMessage(message);
} else if (result.status === "fail") {
  // Content violated guidelines, block it
  return { error: "Your message violates our guidelines." };
} else {
  // Ambiguous case - you choose how to handle
  // Conservative: treat as fail
  // Permissive: treat as pass
  // Balanced: flag for human review
  await flagForReview(message, result);
}

Common Validation Scenarios

Validating LLM Outputs

Guardrails work equally well for checking LLM-generated content before you show it to users. This helps maintain brand safety and compliance:
// Generate a response from your LLM
const llmResponse = await generateResponse(userPrompt);

// Check if the LLM's response contains biased language
const validation = await abv.guardrails.biasedLanguage.validate(
  llmResponse,
  { sensitivity: "high" }
);

// Only show the response if it passes
if (validation.status === "pass") {
  return llmResponse;
} else {
  // Either regenerate or use a fallback message
  return "I apologize, I need to reconsider my response.";
}

Working with Structured Outputs

If your LLM generates JSON, you can validate both the format and schema in one step:
// Your LLM generated this response
const llmOutput = await generateStructuredResponse(prompt);

// Validate it matches your expected schema
const validation = await abv.guardrails.validJson.validate(
  llmOutput,
  {
    schema: {
      name: "string",
      age: "number",
      email: "string",
    },
  }
);

if (validation.status === "pass") {
  // Safe to parse and use
  const data = JSON.parse(llmOutput);
  await saveToDatabase(data);
} else {
  console.error("Invalid format:", validation.reason);
  // Retry with a more explicit prompt
}

Running Multiple Guardrails

You’ll often want to check content against multiple criteria. Run guardrails in parallel to minimize latency:
// Check multiple things at once
const [toxicCheck, biasCheck, formatCheck] = await Promise.all([
  abv.guardrails.toxicLanguage.validate(content),
  abv.guardrails.biasedLanguage.validate(content),
  abv.guardrails.validJson.validate(content),
]);

// All must pass for content to be approved
const allPassed = [toxicCheck, biasCheck, formatCheck].every(
  (result) => result.status === "pass"
);

Monitoring Your Guardrails

Every time you run a guardrail, ABV automatically creates an observation in your dashboard. This lets you:
  • Monitor how often guardrails are failing
  • Analyze what reasons they’re giving
  • Track confidence score distributions
  • Tune sensitivity settings based on real data
  • Identify patterns in validation results
Visit app.abv.dev to view your observations and analyze patterns.

Next Steps