The PredictionGuard SDK provides AIFunction tool wrappers compatible with Microsoft.Extensions.AI. These tools can be used with any IChatClient to give AI models factuality checking, toxicity detection, PII detection, and prompt injection detection capabilities.
Available Tools
Factuality Check
1 2 3 4 5 6 7 8 91011
usingMicrosoft.Extensions.AI;usingPredictionGuard;varpgClient=newPredictionGuardClient(apiKey);vartool=pgClient.AsFactualityCheckTool();// Use with any IChatClient:varoptions=newChatOptions{Tools=[tool],};
Toxicity Check
1
vartool=pgClient.AsToxicityCheckTool();
PII Detection
12345
// Default: replace PII using mask methodvartool=pgClient.AsPiiDetectionTool();// Custom: use fake data replacementvartool=pgClient.AsPiiDetectionTool(replace:true,replaceMethod:"fake");
Injection Detection
1
vartool=pgClient.AsInjectionDetectionTool();
Using Tools with an IChatClient
1 2 3 4 5 6 7 8 910111213141516171819
usingMicrosoft.Extensions.AI;usingPredictionGuard;varpgClient=newPredictionGuardClient(pgApiKey);// Create guardrail toolsvartools=newAITool[]{pgClient.AsFactualityCheckTool(),pgClient.AsToxicityCheckTool(),pgClient.AsPiiDetectionTool(),pgClient.AsInjectionDetectionTool(),};// Use with any IChatClient (e.g., OpenAI, Anthropic, Ollama)varoptions=newChatOptions{Tools=tools};varresponse=awaitchatClient.GetResponseAsync("Check if this text contains PII: My SSN is 123-45-6789",options);