Sensitive information detection for Microsoft Agent Framework
Arcjet Sensitive Information Detection protects against clients sending you sensitive information such as personally identifiable information (PII) that you do not wish to handle.
What is Arcjet?
Arcjet is the AI agent runtime security platform. Discover the agents running in your organization, enforce policy across every action, prompt, and tool call, and keep the evidence to prove what happened. Detect prompt injection, authorize agent tool calls, redact PII, and block bots and abuse.Quick start
Section titled “Quick start”This guide shows you how to configure Arcjet for a
1. Install Arcjet
Section titled “1. Install Arcjet”In your project root, install the SDK:
The helpers are a nested module. Install them with the root Go SDK:
go get github.com/arcjet/arcjet-go@latestgo get github.com/arcjet/arcjet-go/agentframework@latestRequires Go 1.26 or later. That is the framework’s own floor.
Install the Rampart module, which bundles the ~15 MB of model weights for on-device sensitive information detection:
go get github.com/arcjet/arcjet-go/sensitiveinfo/rampart2. Set your key
Section titled “2. Set your key”Create a free Arcjet account. In the Arcjet
Console, select New actor, enter a name, and then select Create. Copy
the Actor key from the actor’s page. It starts with ajkey_.
The Console also shows a Project key that starts with aj_prj_key_. The
SDK can’t use the project key.
Add the actor key to a .env.local file in your project root.
Set ARCJET_KEY in your environment. An empty Key on the Guard client
reads ARCJET_KEY. The Go SDK does not read
ARCJET_ENV.
# Arcjet key for your actor (from <https://console.arcjet.com>).ARCJET_KEY=ajkey_yourkey3. Protect a route
Section titled “3. Protect a route”Create a sensitive info detection rule that scans untrusted text before you
process it. Detection runs on-device with the
Rampart backend.
Agent integrations use localDetectSensitiveInfo from the Guard SDK. You can
change which entity types to detect. For details, see the
reference.
Create the Rampart backend once at startup, then wrap the tool.
package main
import ( "context"
"github.com/arcjet/arcjet-go" "github.com/arcjet/arcjet-go/agentframework" "github.com/arcjet/arcjet-go/sensitiveinfo/rampart" "github.com/microsoft/agent-framework-go/tool" "github.com/microsoft/agent-framework-go/tool/functool")
type noteArgs struct { Note string `json:"note"`}
func saveNote(_ context.Context, in noteArgs) (map[string]string, error) { return map[string]string{"note": in.Note}, nil}
func guardedSaveNote(guard *arcjet.GuardClient) (tool.FuncTool, error) { backend := must(rampart.New(rampart.Options{})) detectPII := must(arcjet.GuardSensitiveInfo(arcjet.GuardSensitiveInfoOptions{ Mode: arcjet.ModeLive, Deny: []arcjet.EntityType{ arcjet.SensitiveInfoEmail, arcjet.SensitiveInfoGivenName, arcjet.SensitiveInfoSurname, }, Backend: backend, })) fn := functool.MustNew( functool.Config{Name: "save_note", Description: "Save a free-text note"}, saveNote, ) return agentframework.GuardTool(guard, fn, agentframework.ToolPolicy{ Action: "note.saved", Rules: agentframework.Args(func(_ context.Context, in noteArgs) ([]arcjet.GuardRuleInput, error) { return []arcjet.GuardRuleInput{detectPII.Text(in.Note)}, nil }), })}
func must[T any](v T, err error) T { if err != nil { panic(err) } return v}4. Test sending personal info
Section titled “4. Test sending personal info”Start your app and try making a request with an email address in the body of the request:
4. Test sending personal info
Invoke the guarded tool with a note that contains a name or email. The call
is denied and the model receives arcjet.GuardDenialResult.
Your logs show this
Arcjet decision ArcjetDenyDecision { id: '', // This will contain the Arcjet request ID ttl: 0, results: [ ArcjetRuleResult { ruleId: '', ttl: 0, state: 'RUN', conclusion: 'DENY', reason: [ArcjetSensitiveInfoReason] } ],...The default response for a request containing unexpected sensitive information is a 400:
< HTTP/2 400< content-type: application/json; charset=utf-8< date: Tue, 09 Jan 2024 13:43:04 GMT< vary: Accept-Encoding< content-length: 72The requests also appear on the actor’s Activity tab in the Arcjet Console.
Detect PHI with a server-side policy
Section titled “Detect PHI with a server-side policy”The on-device detector in the preceding steps covers personal information such as email addresses. Protected health information (PHI) identifiers, such as medical record numbers and health plan member IDs, often have no fixed format. Arcjet’s server-side detector recognizes them from the label next to the value, and an agent guard policy turns each detection into a decision. Use it to stop AI agents receiving PHI and to stop their tools passing it on.
1. Create a PHI policy
Section titled “1. Create a PHI policy”In the Arcjet Console, go to Policies, click
New policy, choose Your application, and enter note.saved as the
label. Then configure the policy:
| Part | Configuration |
|---|---|
| Input | note, a required String evaluated by Arcjet Cloud |
| Detector | phi, Sensitive information running in Arcjet Cloud over note |
| Deny | MEDICAL_RECORD_NUMBER, HEALTH_PLAN_BENEFICIARY_NUMBER, DEVICE_IDENTIFIER, VEHICLE_IDENTIFICATION_NUMBER, LICENSE_PLATE_NUMBER, and SSN |
| Rule | phi-in-note, Live, decided by A detector directly with phi |
A detector rule needs no Rego and no test. Click Save to publish. A label with no published policy denies nothing. For production traffic, start the rule in Dry run, review what it would deny, and then set it live.
Have your coding agent configure it
Connect the Arcjet MCP server and give your agent this prompt:
Create an Arcjet guard policy with the label note.saved.
Declare note as a required SERVER string. Add a server-side sensitiveinformation detector with the ID phi that reads note and deniesMEDICAL_RECORD_NUMBER, HEALTH_PLAN_BENEFICIARY_NUMBER, DEVICE_IDENTIFIER,VEHICLE_IDENTIFICATION_NUMBER, LICENSE_PLATE_NUMBER, and SSN. Add a liveDETECTOR rule, phi-in-note, decided by phi.
Publish it, then show me the guard() call that sends note.To combine PHI detection with other conditions in Rego, see the PHI example policy.
2. Call the policy
Section titled “2. Call the policy”Where you call the policy decides what it protects, and each call type handles an outage differently:
| Call | Runs | Protects | If Arcjet can’t complete the check |
|---|---|---|---|
Direct guard() | Before the model runs | The model | Fails open: the decision is ALLOW, and hasFailedOpen() is true |
| Wrapped tool | When the agent calls a tool | The tool’s destination | Fails closed: the tool doesn’t run |
A direct call to guard() fails open, so you choose how to handle the flow.
Check for a DENY and for a failed-open decision, and decide what each one
does. For PHI, rejecting the text in both cases keeps the check fail-closed.
A wrapped tool, such as one from guardTool(), fails closed, but you choose
what happens in the flow. Set onGuardError to "allow" to run the tool when
Arcjet can’t complete the check. In most frameworks, onDeny sets what the
model receives when the policy denies the call. Python and Go use the
equivalent on_guard_error, OnGuardError, and OnDeny options.
An agent needs both calls: the direct call keeps PHI out of the model, and the wrapper stops a tool that receives PHI anyway. A web app that sends text to a model needs only the direct call.
To detect PHI with Microsoft Agent Framework, call screenNote before the agent
runs, and wrap the tool with agentframework.GuardTool. The wrapper’s action
must match the policy’s label:
package main
import ( "context" "encoding/json" "errors"
"github.com/arcjet/arcjet-go" "github.com/arcjet/arcjet-go/agentframework" "github.com/microsoft/agent-framework-go/tool" "github.com/microsoft/agent-framework-go/tool/functool")
type noteArgs struct { Note string `json:"note"`}
func saveNote(_ context.Context, in noteArgs) (map[string]string, error) { return map[string]string{"note": in.Note}, nil}
var ( errPHI = errors.New("remove health identifiers from the note") errUnchecked = errors.New("couldn't check the note for PHI, try again"))
// screenNote runs before the agent. It rejects a note that carries PHI, so the// model never receives it.func screenNote(ctx context.Context, guard *arcjet.GuardClient, userID, note string) error { decision, err := guard.Guard(ctx, arcjet.GuardRequest{ Label: "note.saved", Actor: &userID, Inputs: map[string]arcjet.GuardPolicyInput{ "note": arcjet.GuardPolicyServerString(note), }, }) if err != nil { return err } if decision.IsDenied() { // The note carries PHI. Ask the user to remove it. return errPHI } if decision.HasFailedOpen() { // Arcjet couldn't complete the check, so the call failed open. Reject // the note to fail closed, or log the error and continue to fail open. return errUnchecked } return nil}
// guardedSaveNote stops the tool if its note carries PHI. The model has// already read this text.func guardedSaveNote(guard *arcjet.GuardClient) (tool.FuncTool, error) { fn := functool.MustNew( functool.Config{Name: "save_note", Description: "Save a free-text note"}, saveNote, ) return agentframework.GuardTool(guard, fn, agentframework.ToolPolicy{ Action: "note.saved", // Fails closed: if Arcjet can't complete the check, the tool doesn't // run. Set arcjet.OnGuardErrorAllow to run the tool anyway. OnGuardError: arcjet.OnGuardErrorDeny, // On a denial, tell the model how to recover. OnDeny: func(arcjet.GuardDecision) any { return map[string]string{ "error": "The note contains health identifiers. Remove them and retry.", } }, // Arcjet's server-side detector reads the note for PHI. Inputs: func(_ context.Context, raw json.RawMessage) (map[string]arcjet.GuardPolicyInput, error) { var in noteArgs if err := json.Unmarshal(raw, &in); err != nil { return nil, err } return map[string]arcjet.GuardPolicyInput{ "note": arcjet.GuardPolicyServerString(in.Note), }, nil }, })}A SERVER input sends the raw note to Arcjet, so sign the BAA before you send
real PHI. For what Arcjet receives and keeps, see
Privacy.
3. Test with PHI
Section titled “3. Test with PHI”Send a note with a labeled medical record number and member ID. Use synthetic values, never real patient records:
Follow-up booked for next week. MRN: 4820193. Member ID: XEH948372615.Arcjet denies the note under phi-in-note. The direct call rejects it before
the model runs, and in an agent, the wrapper stops the tool. For what the detector covers
and its limits, see
Detect protected health information (PHI).
Do I need to run any infrastructure, such as Redis?
No, Arcjet handles all the infrastructure for you so you don't need to worry about deploying global Redis clusters, designing data structures to track rate limits, or keeping security detection rules up to date.
What is the performance overhead?
Arcjet SDK tries to do as much as possible asynchronously and locally to minimize latency for each request. Where decisions can be made locally or previous decisions are cached in-memory, latency is usually <1ms.
When a call to the Cloud API is required, such as when tracking a rate limit in a serverless environment, there is some additional latency before a decision is made. The Cloud API has been designed for high performance and low latency, and is deployed to multiple regions around the world. The SDK will automatically use the closest region which means the total overhead is typically no more than 20-30ms, often significantly less.
What happens if Arcjet is unavailable?
Where a decision has been cached locally, such as blocking a client, Arcjet will continue to function even if the service is unavailable.
If a call to the Cloud API is needed and there is a network problem or Arcjet is unavailable, the default behavior is to fail open and allow the request. You have control over how to handle errors, including choosing to fail close if you prefer. See the reference docs for details.
How does Arcjet protect me against DDoS attacks?
Network layer attacks tend to be generic and high volume, so these are best handled by your hosting platform. Most cloud providers include network DDoS protection by default.
Arcjet sits closer to your application so it can understand the context. This is important because some types of traffic may not look like a DDoS attack, but can still have the same effect. For example, a customer making too many API requests and affecting other customers, or large numbers of signups from disposable email addresses.
Network-level DDoS protection tools find it difficult to protect against this type of traffic because they don't understand the structure of your application. Arcjet can help you to identify and block this traffic by integrating with your codebase and understanding the context of the request, such as the customer ID or the sensitivity of the API route.
Volumetric network attacks are best handled by your hosting provider. Application level attacks need to be handled by the application. That's where Arcjet helps.
What next?
Section titled “What next?”Explore
Section titled “Explore”Arcjet can be used with specific rules on individual routes or as general protection on your entire application. You can set up bot protection, rate limiting for your API, minimize fraudulent registrations with the signup form protection and more.
Get help
Section titled “Get help”Need help with anything? Email support@arcjet.com to get support from our engineering team.