Nyraxis AI

Semantic Kernel

Use Nyraxis as a filter in Microsoft Semantic Kernel to evaluate all chat completions.

Setup

pip install semantic-kernel nyraxis
export NYRAXIS_API_KEY="your-api-key"
export NYRAXIS_PROJECT_ID="your-project-id"

Code Example (Python)

from semantic_kernel import Kernel
from semantic_kernel.filters import FunctionInvocationContext
from nyraxis import Nyraxis

nx = Nyraxis()
kernel = Kernel()

@kernel.filter(filter_type="function_invocation")
async def nyraxis_filter(context: FunctionInvocationContext, next):
    user_input = str(context.arguments)
    result = nx.evaluate(user_input)
    if result.blocked:
        context.result = "Request blocked by policy."
        return
    await next(context)

kernel.add_service(chat_completion_service)

response = await kernel.invoke_prompt("Summarize this: {{$input}}", input="Some text")

Code Example (C#)

using Microsoft.SemanticKernel;
using Nyraxis;

var nx = new NyraxisClient(apiKey: Environment.GetEnvironmentVariable("NYRAXIS_API_KEY"));
var kernel = Kernel.CreateBuilder().AddOpenAIChatCompletion("gpt-4", apiKey).Build();

kernel.FunctionInvocationFilters.Add(async (context, next) =>
{
    var result = await nx.EvaluateAsync(context.Arguments.ToString());
    if (result.Blocked) { context.Result = "Blocked by policy."; return; }
    await next(context);
});

What Gets Protected

  • All function invocations pass through the Nyraxis filter before execution
  • Both prompt inputs and plugin arguments are evaluated against your policies
  • Blocked requests never reach the underlying LLM provider

On this page