Skip to content

Guardrails

Overview

AI safety guardrails API for configuring content moderation and security policies. Set up ban word lists, prompt injection detection, and system prompt leakage prevention. Guardrails apply to all requests from an account and can be tested before deployment.

Available Operations

getGuardrails

Retrieve the current guardrails configuration for the authenticated user. Returns all configured guardrails including ban words, prompt injection detection, and leakage detection settings.

Example Usage

typescript
import { SDK } from "@meetkai/mka1";

const sdk = new SDK({
  serverURL: "https://api.example.com",
  bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await sdk.guardrails.getGuardrails();

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

typescript
import { SDKCore } from "@meetkai/mka1/core.js";
import { guardrailsGetGuardrails } from "@meetkai/mka1/funcs/guardrailsGetGuardrails.js";

// Use `SDKCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const sdk = new SDKCore({
  serverURL: "https://api.example.com",
  bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await guardrailsGetGuardrails(sdk);
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("guardrailsGetGuardrails failed:", res.error);
  }
}

run();

React hooks and utilities

This method can be used in React components through the following hooks and associated utilities.

Check out this guide for information about each of the utilities below and how to get started using React hooks.

tsx
import {
  // Query hooks for fetching data.
  useGuardrailsGetGuardrails,
  useGuardrailsGetGuardrailsSuspense,

  // Utility for prefetching data during server-side rendering and in React
  // Server Components that will be immediately available to client components
  // using the hooks.
  prefetchGuardrailsGetGuardrails,
  
  // Utility to invalidate the query cache for this query in response to
  // mutations and other user actions.
  invalidateAllGuardrailsGetGuardrails,
} from "@meetkai/mka1/react-query/guardrailsGetGuardrails.js";

Parameters

ParameterTypeRequiredDescription
optionsRequestOptionsUsed to set various options for making HTTP requests.
options.fetchOptionsRequestInitOptions that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retriesRetryConfigEnables retrying HTTP requests under certain failure conditions.

Response

Promise<components.GetGuardrailsResponse>

Errors

Error TypeStatus CodeContent Type
errors.APIError4XX, 5XX*/*

updateGuardrails

Update the guardrails configuration for the authenticated user. Configure multiple guardrail modes including ban words (custom word list), prompt injection detection, and system prompt leakage detection. Each guardrail can be individually enabled/disabled with custom thresholds and rejection messages.

Example Usage

typescript
import { SDK } from "@meetkai/mka1";

const sdk = new SDK({
  serverURL: "https://api.example.com",
  bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await sdk.guardrails.updateGuardrails({
    guardrails: [
      {
        mode: "ban_words",
      },
    ],
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

typescript
import { SDKCore } from "@meetkai/mka1/core.js";
import { guardrailsUpdateGuardrails } from "@meetkai/mka1/funcs/guardrailsUpdateGuardrails.js";

// Use `SDKCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const sdk = new SDKCore({
  serverURL: "https://api.example.com",
  bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await guardrailsUpdateGuardrails(sdk, {
    guardrails: [
      {
        mode: "ban_words",
      },
    ],
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("guardrailsUpdateGuardrails failed:", res.error);
  }
}

run();

React hooks and utilities

This method can be used in React components through the following hooks and associated utilities.

Check out this guide for information about each of the utilities below and how to get started using React hooks.

tsx
import {
  // Mutation hook for triggering the API call.
  useGuardrailsUpdateGuardrailsMutation
} from "@meetkai/mka1/react-query/guardrailsUpdateGuardrails.js";

Parameters

ParameterTypeRequiredDescription
requestcomponents.UpdateGuardrailsRequest✔️The request object to use for the request.
optionsRequestOptionsUsed to set various options for making HTTP requests.
options.fetchOptionsRequestInitOptions that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retriesRetryConfigEnables retrying HTTP requests under certain failure conditions.

Response

Promise<components.UpdateGuardrailsResponse>

Errors

Error TypeStatus CodeContent Type
errors.APIError4XX, 5XX*/*

testGuardrails

Test a piece of content against the configured guardrails without making an actual API call. Useful for debugging and validating guardrail configurations. Returns a report indicating whether the content passed and which guardrail was triggered if any.

Example Usage

typescript
import { SDK } from "@meetkai/mka1";

const sdk = new SDK({
  serverURL: "https://api.example.com",
  bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await sdk.guardrails.testGuardrails({
    content: "<value>",
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

typescript
import { SDKCore } from "@meetkai/mka1/core.js";
import { guardrailsTestGuardrails } from "@meetkai/mka1/funcs/guardrailsTestGuardrails.js";

// Use `SDKCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const sdk = new SDKCore({
  serverURL: "https://api.example.com",
  bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await guardrailsTestGuardrails(sdk, {
    content: "<value>",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("guardrailsTestGuardrails failed:", res.error);
  }
}

run();

React hooks and utilities

This method can be used in React components through the following hooks and associated utilities.

Check out this guide for information about each of the utilities below and how to get started using React hooks.

tsx
import {
  // Mutation hook for triggering the API call.
  useGuardrailsTestGuardrailsMutation
} from "@meetkai/mka1/react-query/guardrailsTestGuardrails.js";

Parameters

ParameterTypeRequiredDescription
requestcomponents.TestGuardrailsRequest✔️The request object to use for the request.
optionsRequestOptionsUsed to set various options for making HTTP requests.
options.fetchOptionsRequestInitOptions that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retriesRetryConfigEnables retrying HTTP requests under certain failure conditions.

Response

Promise<components.TestGuardrailsResponse>

Errors

Error TypeStatus CodeContent Type
errors.APIError4XX, 5XX*/*