← Blog

Semantic Kernel Security Patterns: Governing What Your Kernel Sends to the Model

Microsoft Semantic Kernel orchestrates plugins, planners, and memory in your own process. When the kernel needs a model, it calls an AI service connector that reaches an LLM endpoint over HTTP. That connector call is where network security patterns attach. This walks the gateway patterns for a Semantic Kernel deployment: per-identity on the connector, classification of the prompt the kernel assembles from functions and memory, egress control, and a per-decision audit record of what the kernel asked the model.

ByParminder Singh· Founder & CEO, DeepInspect Inc.
Platform & Architectureai-securityllm-securityagentic-aiidentity-and-authorizationpolicy-enforcement

A Semantic Kernel application is orchestration code that runs in your process. You register plugins as functions, wire up a planner that decides which functions to call, attach memory, and build a kernel that ties them together. When a step needs the model, the kernel hands the assembled prompt to an AI service connector, and that connector makes an HTTP call to an LLM endpoint on Azure OpenAI, OpenAI, or another provider. The Microsoft Learn documentation describes the connector as the component that talks to the model service.

That connector call is where network security patterns for Semantic Kernel attach. The planning, the function invocation, the memory reads, and the plugin logic all run inside your runtime, and securing them is an application-security job. The traffic that leaves your environment is the connector's HTTP request to the model, and that is the part a gateway governs.

Separate the in-process kernel from the model call

Before writing controls, draw the line, because the kernel does a great deal that never touches the network.

Inside a gateway's boundary:

  • The connector's HTTP call to the LLM endpoint, carrying the prompt the kernel assembled.
  • A plugin that reaches an external API over HTTP, when that traffic is routed through the gateway.

Outside it:

  • The planner's decision about which functions to run. That logic executes in-process.
  • A native function that runs code on the host. Local execution never reaches a network gateway.
  • Memory reads and writes to a local store.

A gateway governs the connector traffic and any HTTP plugin traffic routed through it. It does not sandbox a native function that runs arbitrary code, and it does not arbitrate the planner. Keep the gateway focused on what crosses the network to a model, and treat the local plugin surface as a separate control problem.

Bind the connector to a per-identity credential

The common Semantic Kernel pattern gives the kernel one API key for its connector. Every function call that reaches the model authenticates as that single credential, so an audit of model traffic cannot distinguish a low-risk summarization function from a function that assembled a prompt full of customer records.

Point the connector at the gateway and give it an identity the gateway can bind to:

[@portabletext/react] Unknown block type "code", specify a component for it in the `components.types` prop

The gateway verifies the token, evaluates policy against that identity, and holds the real provider key so the kernel cannot address the model directly. The audit trail now names the orchestrator identity behind each call. This is the same agent identity discipline that per-agent frameworks need.

Classify the prompt the kernel assembles, not the template you reviewed

A Semantic Kernel prompt is built at runtime from a function template, the arguments passed in, memory recalled from a store, and the output of a prior function in the plan. The developer reviewed the template once. The content that actually leaves for the model is composed on each run, and a recalled memory or an upstream function result can carry data the kernel should not be sending. The gateway classifies the real outbound prompt against regulated data types and applies policy on the data class, which is the control that survives a planner assembling context nobody wrote by hand. The reasoning mirrors LangChain security patterns: inspect the request, do not trust the design.

Constrain egress so a connector cannot bypass the gateway

A per-identity connector credential is meaningless if the process can still open a direct connection to the provider. Restrict egress from the application tier so the only route to any model endpoint runs through the gateway:

[@portabletext/react] Unknown block type "code", specify a component for it in the `components.types` prop

With egress locked, a misconfigured connector or an injected instruction that tries to reach the provider directly fails at the network, and the gateway stays the single path every model call travels. Combined with the identity binding above, this is what makes per-identity policy enforceable rather than advisory.

Record what the kernel asked the model

Every connector call produces a decision record: the kernel identity, the data class in the assembled prompt, the pass-or-block outcome, and the policy version. When a planner chains several functions and each makes its own model call, that sequence of records is what lets a later review reconstruct which step sent which class of data to the model. Each record commits before the response returns, on a write path the application never controls, which is what separates it from a log the same process could edit or lose.

DeepInspect

This is exactly what DeepInspect does. A Semantic Kernel connector makes model calls over HTTP, and DeepInspect sits at that boundary between your kernel and the LLM endpoints it calls.

For every connector request, DeepInspect binds the call to the identity the application supplies, classifies the prompt the kernel assembled against regulated data types, applies the per-identity and per-route policy, and makes a deterministic, fail-closed decision before the request reaches the model. Every decision commits a signed, identity-bound audit record before the response returns, on a write path the kernel never controls. DeepInspect governs the connector traffic and any HTTP plugin traffic routed through it, and it does not claim to sandbox the native functions a kernel runs, which stay an application-security problem. If you are running Semantic Kernel on a shared connector key and cannot say which function sent what to the model, book a demo today.

Frequently asked questions

Can a gateway secure an entire Semantic Kernel application?

No. A Semantic Kernel application runs orchestration in your process: the planner, native functions, and memory all execute locally, and a native function can run code a network gateway never sees. A gateway governs the connector's HTTP call to the model and any HTTP plugin traffic routed through it. The local execution surface is a separate application-security job. The pattern that holds is a gateway on the model boundary plus real controls on the functions the kernel runs.

Why put a per-identity credential on the connector?

Because a single connector key collapses attribution. With one credential across every function that reaches the model, all model traffic looks identical to the provider and to any audit, so no prompt can be tied to the function that produced it. Minting a per-identity token and pointing the connector at a gateway binds each model call to a specific orchestrator identity, which is what makes per-identity policy and a usable audit record possible.

How do you route Semantic Kernel model calls through a gateway?

Set the connector's endpoint to the gateway's base URL and give it a per-identity token instead of the raw provider key. The gateway verifies the token, applies policy, and forwards to the real model endpoint using a key it holds itself. Pair that with egress control that blocks direct connections from the application tier to provider hosts, and the gateway becomes the single path every connector call travels.

Does the gateway stop prompt injection against a Semantic Kernel plan?

Partly, and precision matters. An injected instruction that changes which function the planner runs executes inside your process, outside a network gateway. What the gateway sees is the outbound result: if the injection drives a connector to send a restricted data class to the model or a plugin to reach a disallowed endpoint, identity-bound policy and egress control block and record that call. The gateway does not stop the kernel from being manipulated. It stops a manipulated kernel from moving data it is not authorized to move.