Skip to content

Guard Content

Screen content for prompt injection, jailbreaks, PII, and other threats.

This example assumes using Lakera; is in scope and apiKey contains your Lakera API key.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
using var client = new LakeraClient(apiKey);

// Screen a user message for threats using the Guard endpoint.
var response = await client.GuardAsync(
    messages:
    [
        new GuardMessage
        {
            Role = GuardMessageRole.User,
            Content = "Hello, how are you?",
        },
    ]);

// The response indicates whether the content was flagged.