Obfuscating a Semantic Kernel plugin safely
A [KernelFunction] plugin is a reflection-discovered contract shipped to the LLM as a tool schema. The function name, parameter names, and descriptions are load-bearing; the method body is your IP. Pin the names with attributes so the identifiers rename freely, then let Nebula harden the implementation.
Most “do not obfuscate this” advice is about serialization: a member name is also the wire key, so renaming it breaks the contract. A Semantic Kernel plugin is the same story wearing new clothes. You write a plain C# class, decorate some methods with [KernelFunction], and the Kernel turns that class — by reflection — into a JSON tool schema that it ships to the language model. The function name, the parameter names, and the descriptions are the contract the model reads and calls back against. The method bodies are your intellectual property. Obfuscating a plugin safely is entirely about telling those two apart.
How Semantic Kernel turns a class into tools
A plugin is a class whose methods carry [KernelFunction]. Each method’s signature and attributes become one tool in the schema sent to the model:
using System.ComponentModel;
using Microsoft.SemanticKernel;
public sealed class ForecastPlugin
{
private readonly IWeatherSource _source;
public ForecastPlugin(IWeatherSource source) => _source = source;
[KernelFunction("get_forecast")]
[Description("Gets the multi-day weather forecast for a city.")]
public async Task<string> GetForecastAsync(
[Description("City name, e.g. 'Berlin'.")] string city,
[Description("Number of days, 1-7.")] int days = 3)
{
var readings = await _source.QueryAsync(city, days);
return Blend(readings); // proprietary model-blending — your IP
}
private string Blend(IReadOnlyList<Reading> readings) { /* ... */ }
}
You import it under a plugin name and let the model call it:
var builder = Kernel.CreateBuilder();
builder.Services.AddSingleton<IWeatherSource, NoaaWeatherSource>();
var kernel = builder.Build();
kernel.ImportPluginFromType<ForecastPlugin>("weather");
At call time the Kernel reflects over the plugin and emits a tool definition. With the OpenAI connector it looks like this — note the - separator joining the plugin name to the function name, because OpenAI tool names must match ^[a-zA-Z0-9_-]+$:
{
"type": "function",
"function": {
"name": "weather-get_forecast",
"description": "Gets the multi-day weather forecast for a city.",
"parameters": {
"type": "object",
"properties": {
"city": { "type": "string", "description": "City name, e.g. 'Berlin'." },
"days": { "type": "integer", "description": "Number of days, 1-7." }
},
"required": ["city"]
}
}
}
Every string in that JSON came from reflection: weather from the import call, get_forecast from the attribute, city/days from the parameter names, and the descriptions from [Description]. The CLR identifiers ForecastPlugin, GetForecastAsync, _source, and Blend appear nowhere in it. That separation is the whole opportunity.
The three name tiers
Every identifier in a plugin falls into one of three tiers, and each tier has a different obfuscation answer.
Tier 1 — pin the plugin and function names, then let the identifiers rename
The plugin name and the function name are the model-visible identity of the tool. You make them independent of your CLR names by supplying them as strings:
kernel.ImportPluginFromType<ForecastPlugin>("weather")pins the plugin name to the literal"weather".[KernelFunction("get_forecast")]pins the function name to the literal"get_forecast".
Once both are explicit, the type name and method name carry no contract. An obfuscator can rename ForecastPlugin to p0 and GetForecastAsync to a, and the Kernel still emits weather-get_forecast, because the schema is built from the attribute string and the import string, not from the identifiers. This is exactly the [AliasAs] / [ProtoMember(N)] habit from serialization contracts, applied to tool metadata: pin the wire name and the code name goes free.
Tier 2 — parameter names and descriptions: keep them, don’t hide them
Parameter names are different from the function name, because Semantic Kernel has no attribute to override them — it reads ParameterInfo.Name straight into the schema. So city and days become the schema property keys verbatim. You could let the obfuscator rename them: SK binds the model’s returned arguments back by the same reflected name, so a and b would still round-trip mechanically. Don’t. Two reasons:
- Security value is zero. These names are already sent to the model in plaintext on every call. Renaming them in the binary hides nothing an attacker couldn’t read by watching one request.
- Quality cost is real. The model chooses arguments partly from the property names. A schema of
{ "a": ..., "b": ... }with good descriptions still calls worse than{ "city": ..., "days": ... }. You would be paying accuracy to obscure something already public.
The [Description] strings are in the same tier and take care of themselves. A [Description("...")] argument is stored in the custom-attribute blob in metadata, not as an ldstr in a method body, so string encryption — which rewrites method-body string loads — never touches it. SK reads it by reflection and ships it to the model unchanged. That is the behaviour you want.
Tier 3 — the implementation is the IP
Everything that does not reach the model is where obfuscation earns its keep: the method bodies of your [KernelFunction]s, the private Blend helper, the IWeatherSource abstraction and its NoaaWeatherSource implementation, DTOs like Reading, and every string literal inside those bodies — API routes, prompt fragments, ranking thresholds. Rename them all, flatten the control flow, and encrypt the body strings. None of it is part of the tool schema, so none of it is constrained by the model boundary.
The trap: an unnamed function renames silently
Here is the failure that produces no exception. Suppose you skipped both explicit names:
[KernelFunction] // name defaults to the method name
public async Task<string> GetForecastAsync(...) { }
kernel.ImportPluginFromType<ForecastPlugin>(); // plugin name defaults to the type name
Now the tool identity is derived from your identifiers: the model sees ForecastPlugin-GetForecastAsync. Run the obfuscator and those identifiers rename to p0 and a, so the schema silently becomes:
{ "function": { "name": "p0-a", "parameters": { "properties": { "a": {...}, "b": {...} } } } }
Nothing throws. The Kernel generates the schema from whatever the members are now called and binds responses back by the same names, so a round trip still works. But everything that referred to the tool by its old name is now broken:
- A prompt-template literal like
{{ForecastPlugin.GetForecastAsync $city}}resolves against a function that no longer exists. - System prompts, few-shot examples, and planner hints that name the tool are pointing at a ghost.
- Conversation logs and offline evals keyed on
ForecastPlugin-GetForecastAsyncquietly stop matching.
It is the classic serialization-rename bug: no error, just a contract that moved underneath everyone who depended on it. The fix is Tier 1 — pin the names with strings and the rename becomes invisible to the model.
The Nebula configuration
Because the function identity is pinned by strings, there is almost nothing to keep. You do not need to preserve the plugin type or its method names — those are free to rename. The only thing reflection pulls into the schema that you must protect is parameter names. Scope a preserve rule to the methods that carry [KernelFunction] and let everything else rename. In MSBuild:
<Nebula>
<!-- Plugin name and function names are pinned by string literals
(the ImportPluginFromType("weather") argument and
[KernelFunction("get_forecast")]), so the type and method
identifiers rename freely. The one thing reflection turns into
the model-visible schema is parameter names — keep those. -->
<Preserve parameters="true"
attribute="Microsoft.SemanticKernel.KernelFunctionAttribute" />
</Nebula>
If you drive protection from a nebula.config.json instead, the same intent reads as a narrow keep entry plus full transforms everywhere else:
{
"input": "bin/Release/net8.0/Acme.Ai.Plugins.dll",
"output": "dist/Acme.Ai.Plugins.dll",
"rename": {
"enabled": true,
"renameParameters": true
},
"stringEncryption": { "enabled": true },
"controlFlow": { "enabled": true },
"keep": [
{
"comment": "Keep parameter names on KernelFunction methods — reflection makes them the JSON tool-schema property names the model reads. Type and method names still rename.",
"attribute": "Microsoft.SemanticKernel.KernelFunctionAttribute",
"keepParameters": true
}
]
}
Note what is not in that keep rule: keepName and keepMembers are absent, so the plugin class and its methods rename normally. Then run the protector against the compiled assembly:
nebula protect --config nebula.config.json
Build-time integration is a Nebula Pro feature; the free edition runs the same transforms from the CLI with caps.
Verifying the tool schema is unchanged
The proof that obfuscation did not touch the contract is that the schema the model receives is byte-for-byte the same before and after. Semantic Kernel exposes it without a network call through KernelFunctionMetadata, so you can assert on it directly:
var fn = kernel.Plugins["weather"]["get_forecast"];
var md = fn.Metadata;
Console.WriteLine(md.Name); // get_forecast
Console.WriteLine(string.Join(",", md.Parameters.Select(p => p.Name))); // city,days
Run that against the original assembly, then against the output of nebula protect — with ForecastPlugin renamed to p0, GetForecastAsync renamed to a, the Blend helper renamed and its body flattened, and the route literals inside it encrypted. Both runs print get_forecast and city,days, because the function name came from the attribute string, the parameter names were kept, and the descriptions live in the metadata blob. The model sees an identical tool; your implementation is unreadable.
Summary
A Semantic Kernel plugin is a serialization contract aimed at a language model. Sort every identifier into three tiers: pin the plugin and function names with string arguments so the type and method names rename freely (Tier 1); keep the parameter names and let the descriptions ride in metadata, because the model already reads them and hiding them only costs accuracy (Tier 2); and turn the full weight of renaming, control-flow flattening, and string encryption on the method bodies and helpers that are your actual IP (Tier 3). Pin the names, keep the parameters, harden the rest — and let Nebula Pro protect the implementation while the model never notices.
Try Nebula.NET
Harden your .NET code in minutes — start with the free edition.